3

I am really new in android programming. My question is how does RatingBar actually work? I want to make an app which contain RatingBars on it, and whenever the user rate it like 4 stars, I want the other user of my app too see it. How can I accomplish this? Please help me, I would really appreciate it a lot.

N West
  • 6,768
  • 25
  • 40
user739375
  • 219
  • 3
  • 4
  • 13

6 Answers6

2

For doing this you need a server. When user1 rates with score of 4, then your application posts the score (HTTP POST) to your server (on database or a text file). When user2 starts your application, you request (HTTP REQUEST) your score from server (if there is any).

Reference: Rating bar example, HTTP POST example on Android, HTTP request example

Indrek Kõue
  • 6,449
  • 8
  • 37
  • 69
0
  1. You need to save the ratings say an integer to your server/local DB to set users input.
  2. You can use https://developer.android.com/reference/android/widget/RatingBar.html widget to mark the number of stars.
Shambhavi
  • 51
  • 5
0

In main activity.java we have to create a rating bar object like:

 RatingBar     ratingBar;

Next in the override method, we have to add a view like shown in below:

ratingBar = (RatingBar) findViewById(R.id.idratingBar);

And in the next step:

xml file: inside the relative layout, we have to write:

<RatingBar
android:   stepSize ="0.25"`enter code here`
android:   numStars="5"
android:rating="4.5"/>
CaptainBli
  • 4,121
  • 4
  • 39
  • 58
Jithendra
  • 1
  • 1
0

You can use firebase database for this purpose. It is easy to use and real time database. When user1 gives rating it effects at the same time to other user within the seconds. For your refrence: https://firebase.google.com/docs/android/setup

pooja majoka
  • 136
  • 4
0

RatingBar is just an UI widget which let's you put a 1-5 star, click it and return a value for the star selected.

You have to implement by yourself all the logic of the voting system.

YaW
  • 12,132
  • 3
  • 19
  • 23
-1

In main activity oncreate method inside

RatingBar ratingBar =  findViewById(R.id.ratingbar);

ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
    @Override
    public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {

     Toast.makeText(RatingBarActivity.this,
                    "Rating changed, current rating "+ ratingBar.getRating(), 
                Toast.LENGTH_SHORT).show();
    }
});
CKE
  • 1,533
  • 19
  • 18
  • 29
Pradip
  • 57
  • 1
  • 3