android - disable Listview item click and re-enable it

后端 未结 1 1507
栀梦
栀梦 2021-01-17 10:12

So I have the following code in the adapter:

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


        
相关标签:
1条回答
  • 2021-01-17 10:59

    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.

    0 讨论(0)
提交回复
热议问题