Learn android from scratch (RatingBar scoring component. 23 .)

Source: Internet
Author: User
Tags case statement switch case

Learn android from scratch (RatingBar scoring component. 23 .)
If you want to rate an application, you will often use the components shown in the figure to determine the final score by selecting the number of "five-pointed stars" in Android, you can use the RatingBar component. This component can be used to facilitate user input. The definition structure of the RatingBar class is as follows: java. lang. object? Android. view. View? Android. widget. ProgressBar? Android. widget. AbsSeekBar? Common Methods for android. widget. RatingBar

1 Public RatingBar (Context context) Structure

Create a RatingBar object
2 Public int getNumStars () Normal

Scored quantity
3 Public float getRating () Normal

Get Current Value
4 Public float getStepSize () Normal

Get the set step size
5 Public boolean isIndicator () Normal Determine whether operation is allowed
6 Public void setIsIndicator (boolean isIndicator) Normal Android: isIndicator Can be operated?
7 Public synchronized void setMax (int max) Normal

Set the maximum value
8 Public void setNumStars (int numStars) Normal Android: numStars Set the number of stars
9 Public void setOnRatingBarChangeListener (RatingBar. OnRatingBarChangeListener listener) Normal

Set operation listening
10 Public void setRating (float rating) Normal Android: rating Set Current Value
11 Public void setStepSize (float stepSize) Normal Android: stepSize Set the step size for each increase

XML file
     
      
  
 


JAVA files
Package com. example. ratingbar; import org. w3c. dom. text; import android. OS. bundle; import android. app. activity; import android. widget. ratingBar; import android. widget. ratingBar. onRatingBarChangeListener; import android. widget. textView; public class MainActivity extends Activity {private RatingBar ratingBar; private TextView textView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ratingBar = (RatingBar) this. findViewById (R. id. ratingBar1); textView = (TextView) this. findViewById (R. id. textView1); // sets the listener method ratingBar. listener (new OnRatingBarChangeListener () {@ Overridepublic void onRatingChanged (RatingBar ratingBar, float rating, boolean fromUser) {// TODO Auto-generated method stub // textView append display data // textView. append ("*** current value:" + rating + "** step:" + ratingBar. getStepSize () + "\ n"); // The switch case statement is used to determine the number of stars evaluated. The corresponding operation switch (int) rating) {case 1: textView. setText ("current user rating: Too bad"); break; case 2: textView. setText ("current user rating: Not good"); break; case 3: textView. setText ("current user rating: Good"); break; case 4: textView. setText ("current user rating: Good"); break; case 5: textView. setText ("current user rating: Great"); break; default: break ;}}});}}
First display
Case statement to determine the Display Effect
The scoring component allows users and software developers to provide good feedback and express their opinions on some issues.
Next prediction: Several event processing methods


Related Article

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.