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

标签 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;
    }

这里的问题是:如果我在初始绑定(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/

相关文章:

android - ListView 中的重复数据?

ruby - 没有名为 "activerecord-sqlite3-ruby-adapter"的 gem

ios - 在 iOS 上创建等效的 Android 同步适配器

java - 使用 JNI 从单独的线程调用静态 Java 方法

Android - 如何识别设备是否是 ARM 64

android - ListView onTouchListener 省略了 fling

Android水平动态 ListView

java - 解析 : How to set a pointer in Android?

java - 无法从我的应用程序连接到 IMS apn

java - 数组适配器中出现空指针异常。没有找到 View ?