[英]how to remove selected item from listview using CursorAdapter
buttononclicklistener不起作用,如何從列表中刪除所選項目
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();
}
這樣嘗試,
@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();
}
});
}
另請參閱此鏈接, 如何使用CursorAdapter從ListView刪除選定的項目
在CursorAdapter支持的ListView中刷新數據的另一種可能性是創建一個新的游標並在CursorAdapter上調用swapCursor。
cursor = newCursor();
((CursorAdapter) getListAdapter()).swapCursor(cursor);
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.