Have no bin icon on contextual action bar


#1

I followed the structions of the book ,when I run the criminalItent on a android 4.1 mobile. There is only a icon of right on the left of the contextual bar,but have no the bin icon.
How can fix it ?
thanks a lot


#2

hellllp!!!!!


#3

Are you still stuck on this?

I finished most of this chapter and the contextual menu code worked fine on my 4.4.2 android tablet, so my guess is that somewhere along the way there must be a mistake in your code. Maybe you can post the code you have for crime_list_item_context.xml and CrimeListFragment.java and someone might be able to help. A couple of chapters ago, I had a problem because my code wouldn’t work and it turned out to be as simple as writing Boolean instead of boolean… one capitalization difference and it was spitting errors at me. So likely you think you have the code exactly as in the book, but there’s one tiny difference.


#4

I had the same problem, I think that the code in listing 18.7 in the book doesn’t work anymore with the latest version of android. I had to make a few changes to make it work, here’s what I did:


listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
				@Override
				public boolean onActionItemClicked(
						android.view.ActionMode mode, MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.menu_item_delete_crime:
                        CrimeAdapter adapter = (CrimeAdapter)getListAdapter();
                        CrimeLab crimeLab = CrimeLab.get(getActivity());
                        for (int i = adapter.getCount() - 1; i >= 0; i--) {
                            if (getListView().isItemChecked(i)) {
                                crimeLab.deleteCrime(adapter.getItem(i));
                            }
                        }
                        mode.finish(); 
                        adapter.notifyDataSetChanged();
                        return true;
                    default:
                        return false;
                }
				}

				@Override
				public boolean onCreateActionMode(android.view.ActionMode mode,
						Menu menu) {
                    MenuInflater inflater = mode.getMenuInflater();
                    inflater.inflate(R.menu.crime_list_item_context, menu);
                    return true;
				}

				@Override
				public void onDestroyActionMode(android.view.ActionMode mode) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public boolean onPrepareActionMode(
						android.view.ActionMode mode, Menu menu) {
					// TODO Auto-generated method stub
					return true;
				}

				@Override
				public void onItemCheckedStateChanged(
						android.view.ActionMode mode, int position, long id,
						boolean checked) {
					// TODO Auto-generated method stub
					
				}
            });

#5

What changes did you make? To me, your code looks exactly like 18.7 except for the override annotations and the different order in which you implemented the methods (neither of which should matter.)