所以,我有以下的code。在适配器:
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;
}
在这里问:那么,如果我在初始绑定禁用我的项目,我现在养在屏幕上的活动和需要,使他们所有的无论什么。难道我又重新绑定这一切之后执行该操作?
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?
例如:
onCreate{
// create and bind to adapter
// this will disable items at certain positions
}
onSomeClick{
I need 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 adapter?
}
现在的问题是,我可以有一个很长的列表视图了。它想支持6000项。因此,重新绑定它肯定不是一个选项。
The problem is I can have a really long listview too. It suppose to support 6000 items. So rebinding it certainly is not an option.
感谢
那你的适配器上有一个实例变量:
What about having an instance variable on your adapter:
boolean ignoreDisabled = false;
然后在 areAllItemsEnabled
:
public boolean areAllItemsEnabled() {
return ignoreDisabled;
}
,然后在的IsEnabled
的开头:
public boolean isEnabled(int position) {
if (areAllItemsEnabled()) {
return true;
}
... rest of your current isEnabled method ...
}
然后就可以在两种模式之间通过设置切换 ignoreDisabled
恰当,并呼吁废止
在的ListView
。
请注意,除了的IsEnabled
可能是不必要的;它只是似乎更完整一点。
Note that the addition to isEnabled
is probably unneeded; it just seems a bit more complete.