Note that there are some explanatory texts on larger screens.

plurals
  1. POActionbar contextual in listview
    primarykey
    data
    text
    <p>I am trying to insert a Contextual Action Bar when I click on the item of my ListView. What I want to do is select multiple items in the list and then perform actions on them by clicking on the appropriate icons in the action bar. I wrote this code.</p> <pre><code>applicationListView = (ListView) findViewById(R.id.list); applicationListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); applicationListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { SparseBooleanArray positions = applicationListView.getCheckedItemPositions(); int counter = 0; if (positions != null) { int length = positions.size(); for (int i = 0; i &lt; length; i++) { if (positions.get(positions.keyAt(i))) { counter++; Toast.makeText(getBaseContext(), ""+counter++, Toast.LENGTH_SHORT).show(); } } } startSupportActionMode(mActionModeCallback); } }); private ActionMode.Callback mActionModeCallback = new ActionMode.Callback(){ @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.contextual_action_bar, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_item1: return true; case R.id.menu_item2: //close the action mode //mode.finish(); return true; default: mode.finish(); return false; } } @Override public boolean onPrepareActionMode(ActionMode arg0, Menu arg1) { // TODO Auto-generated method stub arg0.setTitle("Selected item: "); return false; } }; </code></pre> <p>There are various problems.</p> <p>1- When I click on an item appears in the contextual ActionBar but the selected item is NOT highlighted, for example with the color blue. When you select the items is as if the ActionBar was recreated again, as I see the ActionBar icons disappear and reappear, as if, indeed, it was recreated.</p> <p>2- When I click on an item in the toast always visualize the number 1. Why? How can I get a number with the selected items and then to put as the title of action bar?</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.
 

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