Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ActionMode replace Action Items dynamically
    primarykey
    data
    text
    <p>I have implemented an ActionMode via ActionBarSherlock (thanks Jake Wharton for ABS!).</p> <p>Anyways, i am calling the <code>mActionMode.invalidate();</code> each time i click on a ListView item, which also increments/decrements a checkedCounter.</p> <p>Then inside the public boolean <code>onPrepareActionMode(ActionMode mode, android.view.Menu menu)</code> , I have to set the ActionMode contents according to the value of the checkedCounter.</p> <p>Code for the onPrepareActionMode is below : </p> <blockquote> <pre><code> public boolean onPrepareActionMode(ActionMode mode, android.view.Menu menu) { Log.d("ASDASD", "INSIDE ONPREPARE!"); if (mActionMode == null) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.contextualmultiple, menu); return false; } if (checkedCount == 0) { mActionMode.finish(); } else if (checkedCount == 1 &amp;&amp; mActionMode != null) { mActionMode.setTitle(checkedCount + " Message Selected"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.contextualmultiple, menu); return true; } else if (checkedCount &gt; 1) { mActionMode.setTitle(checkedCount + " Messages Selected"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.contextual, menu); return true; } return true; } </code></pre> </blockquote> <p>NOW, the problem is that, when the checkCount is 1, it inflates the menu with say, 3 items in it. But, when the counter increments to 2, it inflates the other menu with 1 item, BUT adds on to the previously inflated menu, without nullifying the contents first. I.E.; now the ActionMode has 2 of previous + 1 of current in the Contextual ActionBar!</p> <p>How can i change my code to remove the previously existing menu items from the ActionMode when the <code>mActionMode.invalidate()</code> is called?</p> <p>P.S. : the onCreateActionMode() function is empty, as the onPrepareActionMode() does everything, including when the mActionMode is null and has a menu to be inflated for the first time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload