我做的活動來更新和刪除從sqlite的數據,第一個應用程序顯示警告對話框顯示選項刪除或更新sqlite的數據,但我每次更新或刪除數據庫,它似乎不起作用。AlertiteDialog SQLite操作不起作用
這是我的適配器代碼:
adapter.setOnClickListener(new OnItemClickListener() {
@Override
public void onClick(View view, int position) {
DataFormNotaPesanan ambil = data.get(position);
final String kodebarang = ambil.getKode();
System.out.println("Kode barang: " + kodebarang);
CharSequence pilihan[] = new CharSequence[] {"Ubah Jumlah", "Hapus"};
AlertDialog.Builder alert = new AlertDialog.Builder(EditFormNotaPesanan.this);
alert.setTitle("Pilih Tindakan");
alert.setItems(pilihan, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which==0){
AlertDialog.Builder ubah = new AlertDialog.Builder(EditFormNotaPesanan.this);
View tampil = EditFormNotaPesanan.this.getLayoutInflater().inflate(R.layout.editjumlah, null);
ubah.setTitle("Masukkan Jumlah");
ubah.setView(tampil);
final EditText jumlah = (EditText)tampil.findViewById(R.id.jumlah);
ubah.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String jumlahpesanan = jumlah.getText().toString();
if(jumlahpesanan.equals("")){
jumlah.setError("Can't blank");
}
else{
helper.ubahJumlahNotaPesanan(kodebarang, jumlahpesanan);
adapter.notifyDataSetChanged();
}
}
});
ubah.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
ubah.show();
}
else if(which==1){
AlertDialog.Builder konfirmasi = new AlertDialog.Builder(EditFormNotaPesanan.this);
konfirmasi.setTitle("Delete Data?");
konfirmasi.setMessage("Are You Sure Delete: " + helper.getNamaBarang(kodebarang));
konfirmasi.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
helper.hapusBarangPesanan(kodebarang);
}
});
konfirmasi.setNegativeButton("Batal", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
konfirmasi.show();
}
}
});
alert.setNegativeButton("Batal", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alert.show();
}
});
,這是我DataBaseHelper:
public void ubahJumlahNotaPesanan(String kodebarang, String jumlah){
String query = "update tmp_orderd set jumlah='" + jumlah + "' where ref_barang='" + kodebarang + "'";
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(query);
}
public void hapusBarangPesanan(String kodebarang){
String query = "delete from tmp_orderd where ref_barang='" + kodebarang + "'";
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(query);
}
在此先感謝
Define _「does not work」_ – sHOLE
如果您重新打開應用程序,操作後會發生什麼? –
@intelliJAmiya什麼也沒有發生,數據是一樣的 –