I was wondering, I have a vertical LinearLayout where I dynamically add horizontal LinearLayouts. Each horizontal LinearLayout contains a CheckBox. I would like to know, how would I retrieve the checked state of each CheckBox in each dynamically added 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
}
});
Aucun commentaire:
Enregistrer un commentaire