package cn.edu.ratingbar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;
import android.widget.RatingBar.OnRatingBarChangeListener;
public class RatingBarActivity extends Activity {
/** Called when the activity is first created. */
private RatingBar ratingBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ratingBar=(RatingBar)this.findViewById(R.id.ratingbar);
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
// TODO Auto-generated method stub
Toast.makeText(RatingBarActivity.this, arg1+"",10).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <RatingBar android:id="@+id/ratingbar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:numStars="4" android:stepSize="1" /> </LinearLayout>