android - disable Listview item click and re-enable it

拜拜、爱过 提交于 2020-01-11 08:04:05

问题


So I have the following code in the adapter:

@Override
    public boolean isEnabled(int position) 
    {
         GeneralItem item = super.getItem(position);
         boolean retVal = true;


            if (item != null)
            {
                if (currSection != some_condition)
                retVal = !(item.shouldBeDisabled());
            }
         return retVal;
     }


    public boolean areAllItemsEnabled() 
    {
        return false;
    }

The question here: So if I disabled my item during initial binding, now I raise the event on the screen and need to enable them all no matter what. Do I rebind it all again after that action is performed?

for instance:

onCreate{

// create and bind to adapter
// this will disable items at certain positions 

}

onSomeClick{

I need the same listview with same items available for click no matter what the conditions of positions are, so I need them all enabled. What actions should I call on the adapter? 

}

The problem is I can have a really long listview too. It supposes to support 6000 items. So rebinding it certainly is not an option.

Thanks,


回答1:


What about having an instance variable on your adapter:

boolean ignoreDisabled = false;

Then in areAllItemsEnabled:

public boolean areAllItemsEnabled() {
    return ignoreDisabled;
}

and then at the beginning of isEnabled:

public boolean isEnabled(int position) {
    if (areAllItemsEnabled()) {
        return true;
    }
     ... rest of your current isEnabled method ...
}

Then you can switch between the two modes by setting ignoreDisabled appropriately and calling invalidate on your ListView.

Note that the addition to isEnabled is probably unneeded; it just seems a bit more complete.



来源:https://stackoverflow.com/questions/5542983/android-disable-listview-item-click-and-re-enable-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!