in data class:
public String getDb(String r_c ){
String dd = new String();
String where = "name" + "=" + r_c;
Cursor cursor = db.query( "info" , null , where , null,null ,null , null);
if(cursor !=null && cursor.moveToFirst()){
do{
dd = (cursor.getString(1)+"\n " + cursor.getString(3)+"\n" + cursor.getString(2)+"\n" + cursor.getString(4));
}
while (cursor.moveToNext());
}
return dd ;
}
public void del(String r_c){
String where = "name" + " = " + r_c;
db.delete("info", where, null);
}
in my activity:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPosition = position;
z = String.valueOf(itemPosition + 1);
final String a = parent.getAdapter().getItem(itemPosition).toString();
String aa = dba.getDb(a);
AlertDialog.Builder ad = new AlertDialog.Builder(view.this);
ad.setTitle("data");
ad.setMessage(aa);
ad.setPositiveButton("ok", null);
ad.setNegativeButton("delet", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dba.del(a);
loadList();
}
});
ad.show();
}
at the first I made it by ID but when I delete any row found that an error of data I just wont to do it by NAME to avoid this problem but it didn't work....
Aucun commentaire:
Enregistrer un commentaire