Reputation: 8531
I'm implementing a custom calendar using a GridView. For this Calendar I have 3 view types, {DAY, TITLE, BLANK}
Is there a way to make certain items in a GridView not clickable?
What I'm trying to avoid is the press state animations for the items that aren't clickable. It ok it the user presses them, I can recognize that it's not the valid view in my onItemClickListener(). This is purely for UI purposes.
Upvotes: 1
Views: 1115
Reputation: 8531
I found the solution. Don't know why I didn't search for ListViews in the first place.
You need to override the isEnabled() Function Returning false will make it non-clickable. True will keep is clickable.
@Override
public boolean isEnabled(int position) {
switch(getItemViewType(position)) {
case CellTypes.BLANK:
case CellTypes.TITLE:
default :
return false;
case CellTypes.DAY:
return true;
}
}
Upvotes: 4
Reputation: 699
In the adapter for your GridView, implement one of the get() method to return a reference to the object being clicked. I'm assuming that your adapter wraps a list of your "Calendar" objects.
In the onItemClickListener for your GridView, call get(index) or get(id) on the adapter to get a reference to the object being clicked. Check its type to see if it is one that you do not wish to be clickable, and return before executing the logic that is usually called when a clickable item is clicked.
Upvotes: 0
Reputation: 911
In XML: android:clickable="false" and in code: setClickable(false);
Upvotes: -1