Android scoring control ratingbar usage instance parsing

No matter games, applications, websites, there are scoring controls. The ratingbar control is provided in the Android SDK to realize the corresponding work.

< ratingbar / > the tag has several common scoring related attributes

Android: numstars, specifies the number of five pointed stars for scoring. Android: rating, specify the current score Android: stepsize, specify the score increment

< ratingbar / > there are also three common style attributes

The default style is ratingbarstyle style. Ratingbarstyleindicator is not interactive. Medium size style ratingbarstylesmall is not interactive. Small stars

No more nonsense, go straight to the code

activity_ main. XML layout file

Running here, we can clearly see the various properties of ratingbar, but how to use the ratingbar for interaction (the first two) and the ratingbar for displaying non interactive (the last two)?

Here, we implement a click on the interactive ratingbar1 above to obtain the score and update it to the ratingbarone for display. Click on the interactive ratingbar2 above to obtain the score and update it to the ratingbartwo for display.

The key method is to set the listening setonrating barchangelistener and set the scoring method (float rating) for the scoring component

After writing and running the code in the activity, click the first two ratingbars. Did you successfully implement the updated two ratingbars? System. out. The values of the three parameters of setonratingbarchangelistener can be clearly seen on the println console output.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>