The ListView is not updated after deletion


#1

After the listing 18.7 the I am getting the contextual action bar with the bin icon but after selecting a crime and clicking on the bin icon do not affect the list, i.e., the item is not deleted and the list is not updated.

Same problem with floating menu also.

Appreciate any help.


#2

Any help please. Stuck on it for 2 days.

This code is not deleting an item(Listing 18.5).

public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info=(AdapterContextMenuInfo)item.getMenuInfo(); int position=info.position; CrimeAdapter adapter=(CrimeAdapter)getListAdapter(); Crime crime=adapter.getItem(position); switch(item.getItemId()) { case R.id.menu_item_delete_crime: CrimeLab.get(getActivity()).deleteCrime(crime); adapter.notifyDataSetChanged(); return true; } return super.onContextItemSelected(item); }

Although after removing the switch case I can delete items. The ID of the MenuItem “item” is 0 that is the reason the control never went in to the case to delete a crime.

[code]public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo info=(AdapterContextMenuInfo)item.getMenuInfo();
int position=info.position;
CrimeAdapter adapter=(CrimeAdapter)getListAdapter();
Crime crime=adapter.getItem(position);

		CrimeLab.get(getActivity()).deleteCrime(crime);
		adapter.notifyDataSetChanged();
		return true;
}[/code]

Someone please help.