PDF for offline use:

Let us know how you feel about this.

Thanks for the feedback!

In this section, you'll create a widget that allows the user to provide a rating, with the RatingBar widget.

  1. Open the Resource\layout\main.xml file and add the RatingBar element (inside the LinearLayout):
    <RatingBar android:id="@+id/ratingbar"

    The android:numStars attribute defines how many stars to display for the rating bar. The android:stepSize attribute defines the granularity for each star (for example, a value of 0.5 would allow half-star ratings).

  2. To do something when a new rating has been set, add the following code to the end of the OnCreate() method:
    RatingBar ratingbar = FindViewById<RatingBar>(Resource.Id.ratingbar);
    ratingbar.RatingBarChange += (o, e) => {
            Toast.MakeText(this, "New Rating: " + ratingbar.Rating.ToString (), ToastLength.Short).Show ();

    This captures the RatingBar widget from the layout with FindViewById<>(int) and then sets an event  method then defines the action to perform when the user sets a rating. In this case, a simple Toast message displays the new rating.

  3. Run the application.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License . This tutorial is based on the Android Form Stuff tutorial .

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.