package .mars_2500_ratingbar; import .; import .; import .; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity { RatingBar ratingBar; Button button1; public static String TAG="MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); ratingBar=(RatingBar)findViewById(.ratingBar1); (new RatingBarChangeListener()); button1=(Button)findViewById(.buttn1); (new ClickListener()); } class RatingBarChangeListener implements OnRatingBarChangeListener { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { (TAG, "Current score="+rating); ("Current score="+rating); } } class ClickListener implements OnClickListener { @Override public void onClick(View v) { //Add 0.5 points to the current (()+0.5f); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(, menu); return true; } }
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:andro android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RatingBar android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5" android:stepSize="0.5" /> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ratingBar1" android:text="score" /> </LinearLayout>
The above is the detailed explanation of the usage of the Android RatingBar control brought to you by the editor. I hope it will be helpful to everyone and support me more~