android - 禁用Listview项目单击并重新启用它

dro*_*ter 14 android listview 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;
    }
Run Code Online (Sandbox Code Playgroud)

这里的问题是:如果我在初始绑定期间禁用了我的项目,现在我在屏幕上引发事件并且无论如何都需要启用它们.在执行该操作后,我是否再次重新绑定它?

例如:

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? 

}
Run Code Online (Sandbox Code Playgroud)

问题是我也可以拥有一个非常长的列表视图.它假设支持6000项.所以重新绑定肯定不是一种选择.

谢谢,

Mat*_*lis 26

在适配器上有一个实例变量怎么样:

boolean ignoreDisabled = false;
Run Code Online (Sandbox Code Playgroud)

然后在areAllItemsEnabled:

public boolean areAllItemsEnabled() {
    return ignoreDisabled;
}
Run Code Online (Sandbox Code Playgroud)

然后在开始时isEnabled:

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

然后你可以通过ignoreDisabled适当的设置和呼叫invalidate你的方式在两种模式之间切换ListView.

请注意,添加isEnabled可能是不必要的; 它似乎有点完整.