如何从列表视图中使用的CursorAdapter删除选定的项目 [英] how to remove selected item from listview using CursorAdapter
本文介绍了如何从列表视图中使用的CursorAdapter删除选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
buttononclicklistener不工作,如何从列表中删除所选的项目
公共无效的onClick(查看为arg0){
//TestDBAdapter.deleteEntry(itemId);
TestDBAdapter.delete(TABLE_NAME,_id =+的itemId,NULL);
Toast.makeText(DisplayActivity.this,你要删除此项目,Toast.LENGTH_SHORT).show();
cursor.requery();
updateList();
notifyDataSetChanged();
}
解决方案
尝试这样,,
@覆盖
公共无效bindView(查看视图,上下文的背景下,最终光标光标){ TextView的txtName的=(TextView中)view.findViewById(R.id.txt_name);
txtName.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_username)));
TextView的txtPassword =(TextView中)view.findViewById(R.id.txt_password);
txtPassword.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_password)));最后弦乐的itemId = cursor.getString(cursor.getColumnIndex(ID)); Button按钮=(按钮)view.findViewById(R.id.btn_delete);
button.setOnClickListener(新OnClickListener(){ 公共无效的onClick(查看为arg0){
Log.d(TAG,点击链接);
deleteRecordWithId(的itemId);
cursor.requery();
notifyDataSetChanged();
}
});
}
也可参考此链接,<一个href=\"http://stackoverflow.com/questions/8416389/how-to-remove-a-selected-item-from-listview-using-cursoradapter\">How使用来自ListView中删除所选项目的CursorAdapter
buttononclicklistener is not working,how to delete the selected item from list
public void onClick(View arg0) {
//TestDBAdapter.deleteEntry(itemId);
TestDBAdapter.delete("TABLE_NAME", "_id="+itemId, null);
Toast.makeText(DisplayActivity.this, "you want delete this item", Toast.LENGTH_SHORT).show();
cursor.requery();
updateList();
notifyDataSetChanged();
}
解决方案
Try like this,,
@Override
public void bindView(View view, Context context, final Cursor cursor) {
TextView txtName = (TextView) view.findViewById(R.id.txt_name);
txtName.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_username)));
TextView txtPassword = (TextView) view.findViewById(R.id.txt_password);
txtPassword.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_password)));
final String itemId = cursor.getString(cursor.getColumnIndex("id"));
Button button = (Button) view.findViewById(R.id.btn_delete);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Log.d(TAG, "Button Click ");
deleteRecordWithId(itemId);
cursor.requery();
notifyDataSetChanged();
}
});
}
also refer this link, How to remove a selected item from ListView using CursorAdapter
这篇关于如何从列表视图中使用的CursorAdapter删除选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文