Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 682
Jack Commonw Avatar asked Oct 02 '12 14:10

Jack Commonw


1 Answers

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.

like image 96
Jordan Kaye Avatar answered Nov 08 '22 03:11

Jordan Kaye