how to get RatingBar value
use this to get rating
(RatingBar)findViewById(R.id.ratingbar1)).setOnRatingBarChangeListener(this);
((RatingBar)findViewById(R.id.ratingbar2)).setOnRatingBarChangeListener(this);
}
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
final int numStars = ratingBar.getNumStars();
mRatingText.setText(
getString(R.string.ratingbar_rating) + " " + rating + "/" + numStars);
}
What you do here is not right: you output the resource id of the rating bar, not its value.
Let me assume that you have earlier done something like:
RatingBar mBar = (RatingBar) findViewById(R.id.mRatingBar);
mBar.setOnClickListener(onclickbutton1);
for example in the activity's onCreate()
. Then within the on click listener you provide, you can get the rating as follows:
public void onClick(View v) {
RatingBar bar = (RatingBar) v;
statusMessage.setText("value is " + bar.getRating());
}
Simple call
ratingBar.getRating() ; GET RATING BAR VALUE
When you want to get the rating value when changed
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
final int numStars = ratingBar.getNumStars();
ratingBar.getRating() ;
final float ratingBarStepSize = ratingBar.getStepSize();
}