checkbox - how to get the sum of selected checkboxes in android? -


i'am newer. problem @ java.

in xml, if have 2 checkboxes, o book o pencil total : . . .

i want sum of selected checkboxes. if book=10 , pencil=5. how?

give each of checkboxes unique id in xml (android:id="@+id/book", android:id="@+id/pencil") , in code check if checked so:

int sum = 0; if (((checkbox)findviewbyid(r.id.book)).ischecked()) sum += 10; if (((checkbox)findviewbyid(r.id.pencil)).ischecked()) sum += 5; 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -