My ActionMode doesn't inflates the menu in onCreateActionMode method

android, android-actionbar, android-actionmode

Solution

You're returning `false` in `ActionMode.Callback.onCreateActionMode`.

From the docs:

Returns

true if the action mode should be created, false if entering this mode should be aborted

Problem

I'm trying display a menu-item in a ActionBar by ActionMode, but neither the ActionMode nor the menu-item aren't shown. Making the LongClickListener of my ListView on the ProvasActivity. ``` this.listView.setLongClickable(true); this.listView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Log.d(null, "ListView Pressionado"); // O action mode está ativado no momento? if (mActionMode != null) { // Cancela o evento return false; } selectedItem = position; mActionMode = ProvasActivity.this .startActionMode(mActionModeCallback); view.setSelected(true); return true; } }); private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Infla o recurso do menu a ser exibido MenuInflater inflater = mode.getMenuInflater(); inflater.inflate( R.menu.linha_selecionada, menu ); Log.d(null, "Menu Inflado"); return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_remover: show(); // Fecha a Action quando executada mode.finish(); break; default: break; } return false; } @Override public void onDestroyActionMode(ActionMode mode) { // Anula o ActionMode mActionMode = null; selectedItem = -1; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } private void show() { Toast.makeText(ProvasActivity.this, "show", Constants.TEMPO_TOAST).show(); Log.d(null, "show()"); } }; ``` My menu for display the ActionMode item (layout/menu/linha_selecionada): ``` <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_remover" android:orderInCategory="100" android:showAsAction="never" android:title="@string/amazenadas"/> </menu> ``` The view of my ProvasActivity (layout/provas_armazenadas.xml): ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" android:orientation="vertical" android:paddingTop="50dp" > <ListView android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/white" android:dividerHeight="4px"/> </RelativeLayout> ``` I'm trying through of Vogella tutorial. http://www.vogella.com/tutorials/AndroidListView/article.html

Original source