【问题标题】:Android Controlling Checked Checkboxes in TableLayoutAndroid 控制 TableLayout 中选中的复选框
【发布时间】:2011-12-13 07:52:00
【问题描述】:

我有一个 TableLayout,我正在动态添加行。在每一行,我也有一个复选框。

我的问题是控制哪些复选框被选中,我什至不知道如何循环每一行。请帮帮我。

【问题讨论】:

    标签: android checkbox dynamic tablelayout


    【解决方案1】:
    Checkbox checkbox;
    
    checkbox = (CheckBox) findViewById(R.id.checkbox);
    
    checkBox.setChecked(false);
    

    还是真的。应该可以,只需将复选框替换为您的变量和@+id

    编辑:

    你可以实现 OnCheckedChangeListener,然后使用类似的东西

    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
        case R.id.checkbox1:
             if (checkbox1.isChecked()){
            //code to use when user checks the box
            }else{
            //code to use when user UNchecks the box
            }
        break;
    
        }
    }
    

    【讨论】:

    • 好的,但我的问题是,对于每一行,我想控制是否选中了复选框。例如在按钮单击事件中。我该怎么做?
    猜你喜欢
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    相关资源
    最近更新 更多