我想知道,我有一个垂直线性布局,在这里我动态添加水平线性布局。每个水平线性布局都包含一个复选框。我想知道,如何在每个动态添加的LinearLayout中检索每个复选框的选中状态?
for (int i = 0; i < array.size(); i++) {
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout testView = (LinearLayout) layoutInflater.inflate(R.layout.balance_test_layout, null);
for (int j = 0; j < customConditions.size(); j++) {
TextView checkView = new TextView(BalanceActivity.this);
checkView.setPadding(padding, padding, padding, padding);
checkView.setTextSize(20);
checkView.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams checkTextParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, getResources().getDisplayMetrics())));
checkTextParams.gravity = Gravity.CENTER;
checkView.setLayoutParams(checkTextParams);
testView.addView(checkView);
}
CheckBox option = (CheckBox) testView.findViewById(R.id.testCheckBox);
option.setId(i);
option.setText(array.get(i));
//code for of rest of LinearLayout
}
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//need to get values of CheckBoxes in here
}
});