android-禁用Listview项目单击并重新启用它 [英] android - disable Listview item click and re-enable it

查看:68
本文介绍了android-禁用Listview项目单击并重新启用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这里的问题:因此,如果我在初始绑定期间禁用了我的项目,那么现在我在屏幕上引发该事件,无论如何都需要启用它们.执行该操作后,我是否会重新重新绑定所有内容?

The 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 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? 

}

问题是我也可以拥有很长的列表视图.它应该支持6000个项目.因此,重新绑定肯定不是一种选择.

The problem is I can have a really long listview too. It supposes 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上调用invalidate来在两种模式之间切换.

Then you can switch between the two modes by setting ignoreDisabled appropriately and calling invalidate on your ListView.

请注意,可能不需要在isEnabled上添加内容.似乎更完整了.

Note that the addition to isEnabled is probably unneeded; it just seems a bit more complete.

这篇关于android-禁用Listview项目单击并重新启用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆