Page 84 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 84

  24 JAM!! Pintar Pemrograman Android
            37:      });
            38:      updateTable();
            39:   }
            40:
            41:   protected void simpKamuta() {
            42:   try {
            43:   dm.addRow(nama.getText().toString(),hobi.getText().toString());
            44:   Toast.makeText(getBaseContext(),
            45:            nama.getText().toString() + ", berhasil disimpan",
            46:            Toast.LENGTH_SHORT).show();
            47:   updateTable();
            48:   kosongkanField();
            49:   } catch (Exception e) {
            50:      e.printStackTrace();
            51:      Toast.makeText(getBaseContext(), "gagal simpan, " +
                e.toString(),Toast.LENGTH_LONG).show();
            52:      }
            53:   }
            54:   protected void kosongkanField(){
            55:      nama.setText("");
            56:      hobi.setText("");
            57:   }
            58:   protected void updateTable() {
            59:      // TODO Auto-generated method stub
            60:      while (tabel4data.getChildCount() > 1) {
            61:            tabel4data.removeViewAt(1);
            62:      }
            63:
            64:      ArrayList<ArrayList<Object>> data = dm.ambilSemuaBaris();//
            65:
            66:      for (int posisi = 0; posisi < data.size(); posisi++) {
            67:            TableRow tabelBaris = new TableRow(this);
            68:            ArrayList<Object> baris = data.get(posisi);
            69:
            70:            TextView idTxt = new TextView(this);
            71:            idTxt.setText(baris.get(0).toString());
            72:            tabelBaris.addView(idTxt);
            73:
            74:            TextView namaTxt = new TextView(this);
            75:            namaTxt.setText(baris.get(1).toString());
            76:            tabelBaris.addView(namaTxt);
            77:
            78:            TextView hobiTxt = new TextView(this);
            79:            hobiTxt.setText(baris.get(2).toString());
            80:            tabelBaris.addView(hobiTxt);
            81:
            82:            tabel4data.addView(tabelBaris);
            83:      }
            84:   }
            85:  }

                    Jika tidak ada error, maka aplikasi AndroidDatabaseSatu
            siap dijalankan.

            PENJELASAN PROGRAM

                              Dapatkan materi terbaru di                   84
                                       www.omayib.com
   79   80   81   82   83   84   85   86   87   88   89