【问题标题】:How to use the isEnabled method to disable child ListView items in android如何使用isEnabled方法在android中禁用子ListView项目
【发布时间】:2017-06-01 11:51:49
【问题描述】:

我想禁用一些列表视图项。我知道我可以在适配器中覆盖它们。但我不明白这部分

// 如果 position == 您要禁用的位置,则返回 false

public boolean isEnabled(int position) {
    // return false if position == position you want to disable
}

你的意思是我把它放在创建 像

if(adapter.isEnabled(0))
{
    adapter.isEnabled(0) == false;
}

默认情况下是真的吗?

我有点迷茫

【问题讨论】:

    标签: android listview


    【解决方案1】:

    ListView 需要一个数据源,你最好对数据源做一些事情而不是在 listView 上做。

        for example :
        public class DataSources{
           private boolean isEnable = false;
           private Other other = ....;
           .....
           getter and setter
    
          }
    
        public class Som....{
    
        listView.setAdapter(new XXAdapter(dataSources){
          //something in your adapter
          if(dataSources.getIsEnable){
             //then  xxx .setOnClickListener..
          }
    
        }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多