how to read and display rating bar value
i[0] // should be selected value
private OnClickListener onclickbutton1 = new OnClickListener() {
public void onCli
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();
}
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);
}
RatingBar ratingBar = (RatingBar) findViewById(R.id.mRatingBar);
RatingBar.setOnClickListener(onclickbutton1);
public void onClick(View v) {
RatingBar bar = (RatingBar) v;
rating.setText("value is " + bar.getRating());
}
var ratingBar = findViewById<RatingBar>(R.id.ratingBarid);
var text1 = findViewById<TextView>(R.id.textViewid)
// rating bar click to show the text view
ratingBar.setOnRatingBarChangeListener(object: RatingBar.OnRatingBarChangeListener{
override fun onRatingChanged(ratingBar: RatingBar?, rating: Float, fromUser: Boolean) {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
text1.text = "Rating bar result $rating"
}
})
var ratingBar = findViewById<RatingBar>(R.id.ratingBarid);
var btn= findViewById<Button>(R.id.buttonid);
var text1 = findViewById<TextView>(R.id.textViewid)
/*
3rd rules of
if (ratingBar!=null){
btn.setOnClickListener {
val msg = ratingBar.rating.toString();
text1.setText("The result of $msg")
}
}
// rating bar click to show the text view
// ratingBar.setOnRatingBarChangeListener(this)
// 1st rules of Rating Bar..
ratingBar.setOnRatingBarChangeListener(object: RatingBar.OnRatingBarChangeListener{
override fun onRatingChanged(ratingBar: RatingBar?, rating: Float, fromUser: Boolean) {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
text1.text = "Rating bar result $rating"
}
})
}
// 2nd rules of Rating bar ....
override fun onRatingChanged(ratingBar: RatingBar?, rating: Float, fromUser: Boolean) {
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
var text1 = findViewById<TextView>(R.id.textViewid)
text1.text = "Rating Bar Result : $rating"
*/
}
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());
}