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
Post a Comment