简体   繁体   中英

How to save RatingBar Rating?

I would like to save the rating bar rating for the user. I was wondering is it possible i could save the value inside of the SQL database or is there a better way?

You can use ratingBar.getRating() to get the rating value (returns a float). This could indeed be saved to an SQL database, but I find it easier to use the preferences if you have a single rating to save.

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    preferences.edit().putFloat("rating", ratingBar.getRating()).commit();

And then you can retrieve the value using

    preferences.getFloat("rating", 0.0f);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM