January 2013
Intermediate to advanced
408 pages
9h 23m
English
The previous recipe introduced you to the checkbox, in particular the star checkbox. One popular use of the star checkbox is to implement a star rating system, whereby users tap on the stars to provide a rating for a particular item (such as user reviews for books, music, or venues). This recipe demonstrates how to implement this rating system.
Assume you have the following code snippet in the activity_main.xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:id="@+id/ratings" > <CheckBox android:id="@+id/star1" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tag="1" /> <CheckBox android:id="@+id/star2" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tag="2" /> <CheckBox android:id="@+id/star3" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tag="3" /> <CheckBox android:id="@+id/star4" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tag="4" /> <CheckBox android:id="@+id/star5" style="?android:attr/starStyle" ...Read now
Unlock full access