Android's Ratingbar control usage _android

Source: Internet
Author: User

Mainactivity.java

Package Com.example.mars_2500_ratingbar;
Import android.support.v7.app.ActionBarActivity;
Import Android.support.v7.app.ActionBar;
Import android.support.v4.app.Fragment;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.LayoutInflater;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.ViewGroup;
Import Android.widget.Button;
Import Android.widget.RatingBar;
Import Android.widget.RatingBar.OnRatingBarChangeListener;

Import Android.os.Build;
  public class Mainactivity extends activity {Ratingbar Ratingbar;
  Button button1;
  public static String tag= "Mainactivity";
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Setcontentview (R.layout.activity_main);
    Ratingbar= (Ratingbar) Findviewbyid (R.ID.RATINGBAR1); Ratingbar.setonratingbarchangelistener (New RatingbarchangelisteneR ());
    button1= (Button) Findviewbyid (R.ID.BUTTN1);
    
  Button1.setonclicklistener (New Clicklistener ()); Class Ratingbarchangelistener implements Onratingbarchangelistener {@Override public void onratingchanged (
      Ratingbar Ratingbar, Float rating, Boolean fromuser) {log.i (TAG, "Current score =" +rating);
    System.out.println ("Current score =" +rating); Class Clicklistener implements Onclicklistener {@Override public void OnClick (View v) {//on current plus 0
    .5 min. ratingbar.setrating (ratingbar.getrating () +0.5f); }} @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; this adds items to th
    E Action Bar if it is present.
    Getmenuinflater (). Inflate (R.menu.main, menu);
  return true; }

}

Activity_main.xml

<?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"
     >
 
<ratingbar 
    android:id= "@+id/ratingbar1"
    Wrap_content "
    android:layout_height=" wrap_content "
    android:numstars=" 5 "
    android:stepsize=" 0.5 "
    />
  <button 
    android:id= "@+id/buttn1"
    android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content"
    android:layout_below= "@id/ratingbar1"
    android:text= "score"
     / >
 </LinearLayout>

The above is a small series for everyone to bring the Android Ratingbar control usage details of the full content, I hope to help you, a lot of support cloud Habitat Community ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.