Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Find Item By ID

Tags:

java

android

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.

like image 682
user590490 Avatar asked Jan 28 '11 16:01

user590490


People also ask

What is the use of Find view by ID in Android?

FindViewById(Int32)Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

How do I get MenuItem on Android?

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.

What does findViewById return?

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 .


1 Answers

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.

like image 72
Ganapathy C Avatar answered Oct 07 '22 04:10

Ganapathy C