1

Android doc said

public abstract void onRatingChanged (RatingBar ratingBar, float rating, boolean fromUser)

Since: API Level 1 Notification that the rating has changed. Clients can use the fromUser parameter to distinguish user-initiated changes from those that occurred programmatically. This will not be called continuously while the user is dragging, only when the user finalizes a rating by lifting the touch.

How can I build an ratingbar that can update as user dragging through it?

I also find ratingBar is not very customziable. The way to change image is some what hack as mentioned here Are there any open sourced ones? Thanks

Community
  • 1
  • 1
Jexcy
  • 594
  • 4
  • 15

4 Answers4

2

This worked for me and I think is the easiest way to do it: Set a onTouchListener on the ratingBar such that on any event, down, move, and up the rating can be broadcasted (ratingBar.getRating() will get you the real time value) to whatever you want to do with it.

SIr Codealot
  • 5,331
  • 9
  • 33
  • 45
2

A very simple solution is this

ratingBar.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        float rating = ratingBar.getRating();

        //todo: do stuff with 'rating' value
        //...

        return ratingBar.onTouchEvent(event);
    }
});
Pranav Raut
  • 401
  • 6
  • 9
1

You will have to set the attribute android:isIndicator=false. This will allow the user to change the rating bar with a drag.

icecreamman
  • 611
  • 1
  • 5
  • 19
  • the callback will only be called after the touch ends. I want the value before touch ends – Jexcy Sep 13 '11 at 20:14
  • Thanks it's working for manually drag the rating bar. If u r not setting this property then some devices are not allowed to drag. – naresh Feb 17 '12 at 08:24
0

Maybe you should use SeekBar? "A SeekBar is an extension of ProgressBar that adds a draggable thumb"

Marc Van Daele
  • 2,856
  • 1
  • 26
  • 52