Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a GridView's choice mode to multiple?

I have this line in my code:

myGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);

It works perfectly fine in ICS, but crashes with 2.2 and 2.3.x with the following error:

java.lang.NoSuchMethodError: android.widget.GridView.setChoiceMode

However a look at the docs tells me that the method is supported from API 1, though it's inherited from AbsListView. I also found this issue that reports the problem with no apparent solution

Does anyone now a workaround to this, or have an idea how to set the choice mode to multiple for all versions?

Thanks

like image 987
znat Avatar asked May 29 '12 20:05

znat


1 Answers

There is no solution to this problem if you intend your code to run on API 10 or earlier, the implementation simply isn't there on those older versions of Android.

If you really want a GridView to have a choice mode you will need write the code yourself. The best place to put the code is in your adapter implementation.

like image 51
satur9nine Avatar answered Oct 11 '22 17:10

satur9nine