Android 单击按钮时选中所有动态创建的复选框
我需要选中在按钮点击时动态创建的所有复选框 这是我的代码:Android 单击按钮时选中所有动态创建的复选框,android,checkbox,Android,Checkbox,我需要选中在按钮点击时动态创建的所有复选框 这是我的代码: layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View addView = layoutInflater.inflate(R.layout.row, null); final
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);
有什么建议吗?您可以使用
checkbox.setChecked(true);
以编程方式选中复选框。您可以在按钮OnClick方法中添加多行 尝试从父布局中获取所有复选框计数,并迭代每个复选框,并将选中值更改为true。感谢您的回答。但如何使用我使用充气器动态创建的10个复选框的答案。private LinearLayout container;LayoutInflater LayoutInflater=(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);最终视图addView=layoutInflater.flate(R.layout.row,null);最终复选框cb_选择_项;cb\u select\u Item=(复选框)addView.findviewbyd(R.id.home\u复选框1);container.addView(addView);