How Can I Prevent Activation For Some ListView Items When The Selection Mode Is MultiChoiceModal?

256 Views Asked by At

I have a customized GridView populated by a customized BaseAdapter. The selection mode of the GridView is MultiChoiceModal. I want to control which items can be activated when long clicked while still ensuring they respond to (short) click events. BaseAdapter has a method called isEnabled, the perfect solution would be if it had a method isActivatable that behaved analogously. The next best solution would be to intercept long clicks and pass them along to the default handler only when acceptable.

Here are some things that don't work:

  1. Overriding isEnabled in the adapter. This is overkill. In that case, the items cease responding to click events.

  2. Calling setLongClickable for the parent view of each item in the adapter's getView method. This is fraught with problems even if it worked. Needless to say it doesn't. Likely a byproduct of the selection mode.

  3. Setting a custom onLongClickListener for the parent view of each item in the adapter's getView method. Android Studio suggests against this when using any AdapterView. It suggests overriding onItemLongClick instead.

  4. Overriding onItemLongClick in the GridView. Evidently, that is also handled for you when in this selection mode.

  5. Setting a custom onItemLongClickListener in the GridView.

While the hive works on this, I am going to try aborting the action mode's creation/blocking activation of prohibited items in the onItemCheckedStateChanged method of my AbsListView.MultiChoiceModeListener. Clearly I'm running low on ideas.

1

There are 1 best solutions below

0
On

I have found a simple solution:

view.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        return true;
    }
});

or

view.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});

where view is the item where you want to prevent a choice mode activation after a long click.