【问题标题】:check all dynamically created checkbox at button click单击按钮时检查所有动态创建的复选框
【发布时间】:2015-08-09 03:03:52
【问题描述】:

我需要检查按钮点击时动态创建的所有复选框。

这是我的代码:

layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        final View addView = layoutInflater.inflate(R.layout.row, null);
                        final Button  ItemName, Item_Qty, Amount, Total, btn_home_checkbox1, btn_home_uncheckbox1;
                      //  final Button slNo;
                        final CheckBox cb_select_Item,cb_unselect_Item;
                        final RelativeLayout checkbox_bg, uncheckbox_bg;
                        slNo = (Button) addView.findViewById(R.id.order_btn_slNo1);
                        ItemName = (Button) addView.findViewById(R.id.order_btn_ItemName1);
                        Item_Qty = (Button) addView.findViewById(R.id.order_btn_Qty1);
                        Amount = (Button) addView.findViewById(R.id.order_btn_amount1);
                        Total = (Button) addView.findViewById(R.id.order_btn_total1);
                        checkbox_bg = (RelativeLayout) addView.findViewById(R.id.order_rl_checkBox1);
                        uncheckbox_bg = (RelativeLayout) addView.findViewById(R.id.order_rl_uncheckBox1);
                        cb_select_Item = (CheckBox) addView.findViewById(R.id.home_checkbox1);
                        cb_unselect_Item = (CheckBox) addView.findViewById(R.id.home_uncheckbox1);

 container.addView(addView);

有什么建议吗?

【问题讨论】:

  • 尝试从父布局中获取所有复选框计数并迭代每个复选框并将选中值更改为true。

标签: android checkbox


【解决方案1】:

你可以使用

checkbox.setChecked(true);

以编程方式检查复选框。您可以在按钮 OnClick 方法中添加多行。

【讨论】:

  • 感谢您的回答。但是我如何使用您的回答来使用充气机动态创建的 10 个复选框。
  • 私有 LinearLayout 容器;LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);最终视图 addView = layoutInflater.inflate(R.layout.row, null); final CheckBox cb_select_Item;cb_select_Item = (CheckBox) addView.findViewById(R.id.home_checkbox1);容器.addView(addView);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-14
  • 1970-01-01
  • 2012-10-24
  • 2021-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多