【问题标题】:Android checking multiple checkboxesAndroid检查多个复选框
【发布时间】:2012-04-24 15:31:11
【问题描述】:
       for(int i=3;i<plates1.length();++i)
        {
            final CheckBox cb=new CheckBox(this);

            JSONObject jObj1 = plates1.getJSONObject(i);
            String date=jObj1.getString("Name");
            cb.setText(date);
            cb.setId(i);
         }

我在这里有我的 for 循环。我已经使用 for 循环创建了复选框,但我无法弄清楚如何使用复选框 ID 一次选择两个复选框的逻辑。你能帮帮我吗?

【问题讨论】:

    标签: android checkbox


    【解决方案1】:
    for(int i=3;i<plates1.length();++i)
            {
                final CheckBox cb=new CheckBox(this);
    
                JSONObject jObj1 = plates1.getJSONObject(i);
                String date=jObj1.getString("Name");
                cb.setText(date);
                cb.setId(i);
                parentView.addView(cb) // you should add it in parent layout
             }
    

    然后这就是您访问它的方式..

    ((CheckBox)parentView.findViewById(3)).setChecked(true) // i took the first check box added
    
    // do the same with others
    

    【讨论】:

    • 谢谢你,桑迪,但我如何将它分配给一个变量?我打算使用 if 循环,当我选择两个复选框时,我将添加一些活动
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2018-03-20
    • 1970-01-01
    相关资源
    最近更新 更多