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:
Overriding
isEnabledin the adapter. This is overkill. In that case, the items cease responding to click events.Calling
setLongClickablefor the parent view of each item in the adapter'sgetViewmethod. This is fraught with problems even if it worked. Needless to say it doesn't. Likely a byproduct of the selection mode.Setting a custom
onLongClickListenerfor the parent view of each item in the adapter'sgetViewmethod. Android Studio suggests against this when using any AdapterView. It suggests overridingonItemLongClickinstead.Overriding
onItemLongClickin the GridView. Evidently, that is also handled for you when in this selection mode.Setting a custom
onItemLongClickListenerin 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.
I have found a simple solution:
or
where
viewis the item where you want to prevent a choice mode activation after a long click.