Jack Commonw
Jack Commonw

Reputation: 395

Set certain item in gridview not clickable

I am trying to set certain items in my gridview from clickable to non clickable. So I have a gridview with a custom adapter on it and a onitemclicklistener. In my Custom adapter, I try to do the following in my getView method: (since I read about calling isEnabled..)

if(int value < 5) { //item can not be clickable
isEnabled(position);
} else {
//other things happen, but isEnabled is not called here in any case
}
//......
@Override
    public boolean isEnabled(int position) {

            return false;

    }

The strange thing is, now every item is not clickable, although there are items where the value is > 5.. I don't know what is causing this...

Upvotes: 5

Views: 3064

Answers (1)

Jordan Kaye
Jordan Kaye

Reputation: 2887

So what you're actually doing here is overriding a built in method isEnabled(int) and telling it to always return false. This is causing your adapter to always tell your grid that its cells should not be enabled.

What you're actually looking for is something more like

public boolean isEnabled(int position) 
{
    if(position < 5)
        return false;
    else
        return true;
}

The key here is that you aren't the one calling isEnabled. You're overriding isEnabled, and the GridView is calling it automatically to determine which cells should be clickable and which should not. So you should never actually call isEnabled anywhere in your code for this purpose.

Upvotes: 9

Related Questions