gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:57:27 26 4
gpt4 key购买 nike

所以我在适配器中有以下代码:

@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;
}

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

例如:

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?

}

问题是我也可以有一个很长的 ListView 。它应该支持 6000 个项目。所以重新绑定(bind)它当然不是一种选择。

谢谢,

最佳答案

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

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 上调用 invalidate 来在两种模式之间切换。

请注意,可能不需要添加到 isEnabled;它看起来更完整一些。

关于android - 禁用 Listview 项目单击并重新启用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5542983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com