我有简单的列表视图,它显示名称和编号(此数据实际上来自数据库)。当我尝试删除其工作正常(对于数字字段为“123456”)但问题无法删除一些数字字段为“888-888-00”的列表项
这里添加了我的代码......请帮帮我......,
数据库助手.java
private static final String KEY_NAME = "name";
private static final String KEY_NUMBER = "number";
public void deleteContacts(String name, String number){
//Raw Query wont work for Deletion
db = this.getWritableDatabase();
System.out.println("deleted number: "+number+"name: "+name);
String deleteQuery = "Delete from "+CONTACTS_TABLE_NAME+" where "+KEY_NUMBER+" = "+number;
//db.rawQuery("Delete from "+CONTACTS_TABLE_NAME+" where "+KEY_NUMBER+" = "+number, null);
db.execSQL(deleteQuery);
db.close();
}
MainActivity.java
在 oncreate() 方法内部包含,
selectedListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
final HashMap<String, String> toDelete = (HashMap<String, String>) selectedListView.getItemAtPosition(position);
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(MainActivity.this);
deleteDialog.setTitle("Confirm Delete...");
deleteDialog.setMessage("Are you sure you want delete this '"+toDelete.get("name")+"' Contact?");
deleteDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dataBaseHelpher.deleteContacts(toDelete.get("name"), toDelete.get("number"));
dialog.dismiss();
updateList();
}
});
deleteDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
deleteDialog.show();
}
});