While click the button i have added a checkbox, finally need to get the all checked checkbox value by means of clicking submit button,
This is my code
mIncrementButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 0, 0);
CheckBox checkbox = new CheckBox(MainActivity.this);
checkbox.setLayoutParams(params);
mAllText.add(checkbox);
checkbox.setText("Checkbox" + j);
checkboxlayout.addView(checkbox);
j++;
Log.d("j", "--->" + j);
}
});
mGetTheVlue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Inside Button", "Inside Burron" + mAllText.size());
for (int i = 0; i < mAllText.size(); i++) {
CheckBox check = mAllText.get(i);
if (check.isChecked()) {
AllCheckbox.add(check.getText().toString());
}
}
}
});
Now i need to check whether all checkbox are checked and need to get the values, Dont know whether this question is so old or not. but i dint get any solution from google kindly help to get the solution.
Thanks in advance.
Also you don't need to store all CheckBox in Collection. You can just get the child views from layout and check each of them if it is CheckBox.
mGetTheVlue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Inside Button", "Inside Burron" + checkboxlayout.getChildCount());
for(int i=0; i<checkboxlayout.getChildCount(); i++) {
View nextChild = checkboxlayout.getChildAt(i);
if(nextChild instanceOf CheckBox)
{
CheckBox check = (CheckBox) nextChild;
if (check.isChecked()) {
AllCheckbox.add(check.getText().toString());
}
}
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With