It seems you would like to be informed whenever users set the rating, so you would need OnRatingBarChangeListener
not OnClickListener
.
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
}
});
Note: onClick
method of OnClickListener
interface is getting called by another method called performClick()
. This method is declared in the View
class, so click event all is handled in View
class. However RatingBar
overrides internal touch event callbacks and does not allow the root class (i.e. View
) to be informed. So, the underlying View
cannot detect click events anymore. A workaround nevertheless, could be in this post.