//删除所有数据代码,可以实现
public long DeleteAllSms() {
open();
return db.delete(DB_TABLE_COURSE,null,null);
}//删除一项数据,却不能,函数始终返回0
public int removeSubject(int index) {
open();
String where = KEY_ID+"="+index;
return db.delete(DB_TABLE_COURSE,where, null);
}大家觉得可能是哪方面的问题呢,有没有遇到这问题的兄弟姐妹,真心求教!!!
public long DeleteAllSms() {
open();
return db.delete(DB_TABLE_COURSE,null,null);
}//删除一项数据,却不能,函数始终返回0
public int removeSubject(int index) {
open();
String where = KEY_ID+"="+index;
return db.delete(DB_TABLE_COURSE,where, null);
}大家觉得可能是哪方面的问题呢,有没有遇到这问题的兄弟姐妹,真心求教!!!
key_id 确认存在?
private static final String TB_CREATE_COURSE = "CREATE TABLE "+
DB_TABLE_COURSE+" ("+KEY_ID+" Integer primary key autoincrement,"+
KEY_DAY_OF_WEEK +" text not null," +
KEY_START_WEEK+" text not null,"+
KEY_END_WEEK +" text not null,"+
KEY_TEACHER_NAME+" text not null,"+
KEY_COURSE_NAME +" text not null,"+
KEY_TEACH_PLACE+" text not null,"+
KEY_CURRENT_WEEK+" text not null,"+
KEY_START_LESSION_TIME+" text,"+
KEY_END_LESSION_TIME +" text);";
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
selectedItem = arg2;
new AlertDialog.Builder(AnimationTest.this).setIcon(R.drawable.icon).
setTitle("课程设置").setPositiveButton("删除课程",
//创建DialogInterface.OnClickListener对象实例,当单击按钮时调用onClick方法
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println(dbAdapter.removeSubject(selectedItem)+"返回值");
if(dbAdapter.removeSubject(selectedItem)>0) {
simpleAdapter.notifyDataSetChanged();
listView.setAdapter(simpleAdapter);
Toast.makeText(AnimationTest.this, "删除成功", Toast.LENGTH_SHORT).show();
}
else {
System.out.println("删除不成功");
System.out.println(selectedItem);
}
}
}).setNegativeButton("更改课程",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create().show();
}
});
一目了然