谁能帮我在列表中执行长按选项
查看项目的信息,以便我能够从sq lite数据库中删除我的注释... i
在我的笔记应用程序中有2列,分别是id,title和notetext
我创建表的代码是..
mydb1 = Main1Activity.this.openOrCreateDatabase("185", MODE_PRIVATE, null);
mydb1.execSQL("CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY AUTOINCREMENT,title varchar,notetext varchar);");
长按代码
lv.setOnItemLongClickListener(new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
data.remove(arg2);
// adapter.notifyDataSetChanged();
//adapter.notifyDataSetInvalidated();
return true;
}
});
最佳答案
是的,我得到了答案...这将对其他堆栈流用户有用:D :)
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
ArrayAdapter <String> adapter = new ArrayAdapter<String>
(menu.this,android.R.layout.simple_list_item_1,data);
Cursor cursor2=mydb1.rawQuery("SELECT * FROM notes;", null);
data.remove(arg2);
lv.setAdapter(adapter);
cursor2.moveToPosition(arg2);
int id= cursor2.getInt(cursor2.getColumnIndex("id"));
mydb1.delete("notes", "id=?", new String[] {Integer.toString(id)});
return true ;
}
关于android - 长按方法从 ListView 中删除项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20932149/