点击按钮检查所有动态创建的复选框

时间:2015-05-27 07:10:36

标签: android checkbox

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

这是我的代码:

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);

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您可以使用

checkbox.setChecked(true);

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