在CustomAdapter中隐藏或显示CheckBox

时间:2017-05-22 13:40:43

标签: android listview checkbox custom-adapter

我在我的应用中使用数据库。我可以创建一些"笔记" ,并定义类型:家庭作业或测试。

然后我在ListView中显示它。 但是,当创建行时,我想检查我是否选择了" Homework"作为类型,如果我这样做,我会在listView中为该行添加一个复选框,但如果我选择" Test",则不会显示CheckBox。

然后,通过复选框,我可以使用cb.isChecked()将作业设置为DONE或NOT DONE。但首先我必须只显示复选框,如果它是一个功课。但我不知道怎么检查它..

我该怎么做?

这是我的CustomAdapter类

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

}

谢谢你们!

3 个答案:

答案 0 :(得分:1)

你必须在bindview方法中检查它

sys_notes

答案 1 :(得分:1)

你的病情不好。在适配器{{1}}方法中:

使用:

{{1}}

代替:

{{1}}

答案 2 :(得分:0)

步骤

  1. 在XML行中,make复选框隐藏
  2. 机器人:能见度= “水涨船高”

    1. 在bindview方法中

      @Override
      
          public void bindView(View view, final Context context, final Cursor cursor) {
      
      
              super.bindView(view, context, cursor);
      
          LinearLayout root_view=LinearLayout)view.findViewById(R.id.item_root);
      
      root_view.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
      
              //method
          }
      });
      
      
      CheckBox cbdevoir = (CheckBox)view.findViewById(R.id.CBDevoir);
      
      If(type.equals("Homework"){
      
        cbdevoir.setVisibility(View.VISIBLE)
       }
      else{
      
          cbdevoir.setVisibility(View.GONE);
      }
      
      
      if(cbdevoir.isChecked())
      {
          //method to set the homework done
      }
      else
          {
              //method to set the homework undone
          }
      }