RatingBar for android control development

Source: Internet
Author: User

RatingBar for android control development
RatingBar for android control developmentThis blog post mainly describes the development of RatingBar. This control is mainly used for scoring and rating. Let's take a look at the instance code below:
MainActivity. java:Package com. example. ratingbar;


Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. Menu;
Import android. widget. RatingBar;


Public class MainActivity extends Activity {


Private RatingBar ratingBar = null;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

RatingBar = (RatingBar) findViewById (R. id. myRatingBar );
// Bind the listener of the RatingBar
RatingBar. setOnRatingBarChangeListener (new setRatingBarListener ());
}


// Create a listener for RatingBar
Class setRatingBarListener implements RatingBar. OnRatingBarChangeListener {



// Call this method when the RatingBar Level Changes
@ Override
Public void onRatingChanged (RatingBar ratingBar, float rating,
Boolean fromUser ){
// TODO Auto-generated method stub
System. out. println ("RatingBar --->" + rating );
}

}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. main, menu );
Return true;
}


}


Main. xml: Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: paddingBottom = "@ dimen/activity_vertical_margin"
Android: paddingLeft = "@ dimen/activity_horizontal_margin"
Android: paddingRight = "@ dimen/activity_horizontal_margin"
Android: paddingTop = "@ dimen/activity_vertical_margin"
Tools: context = ". MainActivity">


Android: id = "@ + id/myText"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello_world"/>


Android: id = "@ + id/myRatingBar"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/myText"
Android: numStars = "4"
Android: stepSize = "0.5"/>




The display effect is as follows:

You can change the increment by setting stepSize.



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.