3 Replies - 571 Views - Last Post: 23 July 2017 - 09:25 PM

#1 mr.nacho  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 208
  • Joined: 28-December 12

Contextual Action Bar for AppCompatActivity not working

Posted 15 July 2017 - 10:13 PM

I've been following this code snippet provided by the documentation:

Enabling batch contextual actions in a ListView or GridView

ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

    @Override
    public void onItemCheckedStateChanged(ActionMode mode, int position,
                                          long id, boolean checked) {
        // Here you can do something when items are selected/de-selected,
        // such as update the title in the CAB
    }

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        // Respond to clicks on the actions in the CAB
        switch (item.getItemId()) {
            case R.id.menu_delete:
                deleteSelectedItems();
                mode.finish(); // Action picked, so close the CAB
                return true;
            default:
                return false;
        }
    }

    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        // Inflate the menu for the CAB
        MenuInflater inflater = mode.getMenuInflater();
        inflater.inflate(R.menu.context, menu);
        return true;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {
        // Here you can make any necessary updates to the activity when
        // the CAB is removed. By default, selected items are deselected/unchecked.
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
        // Here you can perform updates to the CAB due to
        // an invalidate() request
        return false;
    }
});


I use this code to set the toolbar for AppCompatActivity and I even added "windowActionModeOverlay" for the Theme.AppCompat.Light.NoActionBar that I am using but still, it is not working.

        Toolbar toolbar = (Toolbar) findViewById(R.id.custom_toolbar);
        setSupportActionBar(toolbar);

        final ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setTitle("My List");
        }


What am I missing here?

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Contextual Action Bar for AppCompatActivity not working

#2 wseng92  Icon User is online

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 284
  • Joined: 23-September 15

Re: Contextual Action Bar for AppCompatActivity not working

Posted 16 July 2017 - 07:14 PM

What did you mean by not working ? Icon not displaying?
Was This Post Helpful? 0
  • +
  • -

#3 mr.nacho  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 208
  • Joined: 28-December 12

Re: Contextual Action Bar for AppCompatActivity not working

Posted 16 July 2017 - 07:26 PM

View Postwseng92, on 16 July 2017 - 07:14 PM, said:

What did you mean by not working ? Icon not displaying?


If I long press the listview item, it does nothing.
Was This Post Helpful? 0
  • +
  • -

#4 wseng92  Icon User is online

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 284
  • Joined: 23-September 15

Re: Contextual Action Bar for AppCompatActivity not working

Posted 23 July 2017 - 09:25 PM

View Postmr.nacho, on 17 July 2017 - 02:26 AM, said:

If I long press the listview item, it does nothing.

You have to set setOnItemLongClickListener() in the ListView.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1