Reputation: 49
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();
}
Upvotes: 0
Views: 2156
Reputation: 21
Other possibility of refresh data in a CursorAdapter backed ListView is to create a new cursor and call swapCursor on CursorAdapter.
cursor = newCursor();
((CursorAdapter) getListAdapter()).swapCursor(cursor);
Hope this can help.
Upvotes: 0
Reputation: 12134
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
Upvotes: 1