how to read and display rating bar value
i[0] // should be selected value
private OnClickListener onclickbutton1 = new OnClickListener() {
public void onClick(View v) {
int[] i = new int[]{ R.id.mRatingBar};
statusMessage.setText("value is " + i[0]);
}
};
// this works
private OnClickListener onclickbutton1 = new OnClickListener() {
public void onClick(View v) {
RatingBar mBar = (RatingBar) findViewById(R.id.mRatingBar);
float[] i = new float[]{ mBar.getRating() };
statusMessage.setText("value is.. " + i[0]);
}
};
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:
for example in the activity’s
onCreate(). Then within the on click listener you provide, you can get the rating as follows: