Bring up CAB with a short click

129 Views Asked by At

I have a ListView with a number of items on it. When I long click on one of the items, it brings up a CAB and I can select a number of these items and perform group operations on them. This is dandy. I currently set a MultiChoiceModeListener on my ListView to achieve this (and have put the relevent code to that effect below).

Is it possible for this CAB to be brought up from a short click, rather than a long click?

public class ViewInventoryActivity extends ActionBarActivity
{
    private ArrayList<InventoryEntry> list;
    private ListView listView;
    private ListViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_inventory);

        list = getList();
        listView = (ListView) findViewById(R.id.listview_inventory);
        adapter = new ListViewAdapter(this, R.layout.listview_inventory_row, list);
        // This is a custom written adapter

        listView.setAdapter(adapter);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

        listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener()
        {
            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked)
            {
                mode.setTitle(listView.getCheckedItemCount() + " selected");
                adapter.toggleSelection(position);
                // toggleSelection keeps track of what is currently selected
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu)
            {
                mode.getMenuInflater().inflate(R.menu.menu_view_inventory, menu);
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item)
            {
                return false;
                // This does have some logic, but it's not important here
            }

            @Override
            public void onDestroyActionMode(ActionMode mode)
            {
                adapter.removeSelection();
            }

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu)
            {
                return false;
            }
        });
    }
}
0

There are 0 best solutions below