sqliteからデータを更新および削除するアクティビティを作成します。最初のアプリケーションでは、sqliteのデータを削除または更新する警告ダイアログが表示されますが、データベースを更新または削除すると、動作しません。AlertDialog内の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);
}
おかげ
_ "動作しません" _ – sHOLE
あなたの操作の後で、あなたのアプリを開いた後に何が起こるのですか? –
@intelliJAmiya何も起こりません、データは同じです –