可以任何一个能帮助我,如何执行列表中长按选项 鉴于项目的,所以我能够从平方删除我的笔记精简版数据库...我 有2列在我的笔记应用程序,他们是ID,标题和notetext
我的code创建表。
MYDB1 = Main1Activity.this.openOrCreateDatabase(185,MODE_PRIVATE,NULL);
mydb1.execSQL(CREATE TABLE IF NOT EXISTS笔记(ID INTEGER PRIMARY KEY AUTOINCREMENT,标题为varchar,notetext VARCHAR););
长按code
lv.setOnItemLongClickListener(新OnItemLongClickListener(){
公共布尔onItemLongClick(适配器视图<>为arg0,查看ARG1,INT ARG2,长ARG3){
data.remove(ARG2);
// adapter.notifyDataSetChanged();
//adapter.notifyDataSetInvalidated();
返回true;
}
});
解决方案
是的,我得到了答案......这将是其他堆栈流量用户的帮助:D :)
公共布尔onItemLongClick(适配器视图<>为arg0,查看ARG1,INT ARG2,长ARG3){
ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>
(菜单。该,android.R.layout.simple_list_item_1,数据);
光标光标2 = mydb1.rawQuery(SELECT * FROM笔记;,NULL);
data.remove(ARG2);
lv.setAdapter(适配器);
cursor2.moveToPosition(ARG2);
INT ID = cursor2.getInt(cursor2.getColumnIndex(ID));
mydb1.delete(票据,ID =?,新的String [] {Integer.toString(ID)});
返回true;
}
could any one help me that how to perform long click option in list view item's so i able to delete my notes from sq lite database ...i have 2 column in my note app they are id ,title and notetext
my code to create table is ..
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);");
long click code
lv.setOnItemLongClickListener(new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
data.remove(arg2);
// adapter.notifyDataSetChanged();
//adapter.notifyDataSetInvalidated();
return true;
}
});
解决方案
yes i got the answer... it will be helpful for other stack flow user's :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 ;
}