我有这样的方法:
public void initialiseCheckBox(){
ArrayList<String> list = new ArrayList<String>();
list.add("Banners");
list.add("Poster");
list.add("Stickers");
for(int i = 0; i < list.size(); i++) {
checkBox = new CheckBox(getActivity());
checkBox.setId(i);
checkBox.setText(list.get(i));
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.rightMargin = 32;
params.topMargin = 5;
checkBox.setOnClickListener(getOnClickDoSomething(checkBox));
linearMain.addView(checkBox, params);
}
}
我可以通过getOnClickDoSomething(checkBox)获取所有选定的CheckBox
现在如何使用片段取消选中不同方法中的所有已检查CheckBox
。谢谢
答案 0 :(得分:3)
试试这个:
首先填充复选框的ArrayList:
ArrayList<CheckBox> arrayOfCheckBox = new ArrayList<>();
for(int i = 0; i < list.size(); i++) {
checkBox = new CheckBox(getActivity());
checkBox.setId(i);
checkBox.setText(list.get(i));
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.rightMargin = 32;
params.topMargin = 5;
checkBox.setOnClickListener(getOnClickDoSomething(checkBox));
arrayOfCheckBox.add(checkBox);
linearMain.addView(checkBox, params);
}
然后取消选中arraylist的复选框:
for (int i = 0; i < myCheckBoxes.size(); i++) {
myCheckBoxes.get(i).setChecked(false);
}
请告诉我是否解决您的问题。(已解决)