Overrides in BaseAdapter with GridView not called by super class
I am starting a new thread based on Cannot enable/disable clickable TextView inside GridView.
I found out that the overrides isEnabled and areAllItemsEnabled from BaseAdapter will only be called if the Adapter is attached to a ListView, but not to a GridView:
Here these 2 overrides will NOT be called:
gridview.setAdapter(new MyCustomAdapter(this));
However, here they will be called:
listview.setAdapter(new MyCustomAdapter(this));
So, now back to my original question (see above): How can I toggle the enabled-state of my GridView items (such as enabled/disable TextVi开发者_如何学JAVAews as my items)? Is there a workaround? Thanks!
I found out that the overrides isEnabled and areAllItemsEnabled from BaseAdapter will only be called if the Adapter is attached to a ListView, but not to a GridView
Correct. While those methods are implemented on Adapter
, they are a feature of ListView
, not of AdapterView
.
How can I toggle the enabled-state of my GridView items (such as enabled/disable TextViews as my items)?
There is no "enabled-state of my GridView items", AFAIK. If they are in the GridView
, they are enabled. You are welcome to create your own clone of GridView
that attempts to implement the stuff you'll find in lookForSelectablePositionOnScreen()
in the ListView implementation, but this is unlikely to be easy.
I suggest either not putting non-selectable items in the GridView
in the first place, or settling for visually altering them (e.g., graying them out) and ignoring them if the user taps on them.
I was looking for a way to disbale Items/Views in my GridView.
I'm extending a BaseAdapter and added
@Override
public boolean isEnabled(int position) {
System.out.println("isEnabled?");
if (position == 0)
return true;
return MyPreferences.getInstance(context).isLessonAccessible(validLessons.get(position));
}
The first Entry is always supposed to be enabled, and for every other item im Checking if it is supposed to be enabled. The Method is called every time you click an Item in your GridView. I supposed the same rule applies to a listview as well.
精彩评论