The RatingBar in ANDROID

By | February 7, 2011

Simply copy and paste the following code to see how to use the RatingBar in ANDROID.

package AndroidRatingBar.pack;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;

public class AndroidRatingBar extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       final RatingBar ratingBar_Small = (RatingBar)findViewById(R.id.ratingbar_Small);
       final RatingBar ratingBar_Indicator = (RatingBar)findViewById(R.id.ratingbar_Indicator);
       final RatingBar ratingBar_default = (RatingBar)findViewById(R.id.ratingbar_default);

       ratingBar_default.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){

   @Override
   public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

    ratingBar_Small.setRating(rating);
    ratingBar_Indicator.setRating(rating);
    Toast.makeText(AndroidRatingBar.this, "rating:"+String.valueOf(rating),
      Toast.LENGTH_LONG).show();
   }});
   }
}

Leave a Reply

Your email address will not be published. Required fields are marked *