Ok I have a very simple and yet difficult question.
I have 10 checkboxes, all called 'check', each one has a unique id from 1 - 10. When I press a button on my app I want to be able to tell which checkboxes are checked and which aren't.
I'm sure the answer is very simple but I can't think of how I can do this. I have the code for the button, I can't work out how to check each checkbox by id when they are all called 'check'. Hopefully one of you guys can help me out.
FindViewById(Int32)Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .
Here's a quick example of how to access an Android MenuItem in a Java Activity or Fragment class (i.e., in your Java code). you can access the MenuItem with the id menuItemPinQuote like this in your Android/Java code: public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater. inflate(R.
findViewById returns an instance of View , which is then cast to the target class. All good so far. To setup the view, findViewById constructs an AttributeSet from the parameters in the associated XML declaration which it passes to the constructor of View . We then cast the View instance to Button .
try this,
in OnClickListener of your button add the following code
boolean checkedState[] = new boolean[10];
for(int i=0; i <= 10; i++)
{
CheckBox c = (CheckBox)findViewById(i);
checkedState[i] = c.isChecked();
}
let me know what happened.
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