问题
I have a requirement to rate for a user with minimum of one star and after that ratings should increase to 0.5. But my question is that the user should not change the minimum rating of star to 0.5 or 0. 1 should be the default rating. Please help with this and awaiting for your earlier response. I also tried implementing by listeners from the link but completely struct with the logic inside My code is:
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
}
});
回答1:
Setting Rating takes float value , in Case ur value is String :
ratingBar.setRating(Float.parseFloat(result));
回答2:
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
if(rating<1.0f)
ratingBar.setRating(1.0f);
}
});
回答3:
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
ratingBar.setRating(Float.parseFloat(""+Math.ceil(rating)));
}
}
回答4:
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(RateUsProductActivity.this,"Rating :- "+String.valueOf(rating),Toast.LENGTH_SHORT).show();
if(rating<1.0f)
ratingBar.setRating(1.0f);
}
});
When Rating is less than 1 then automatically set Rating 1
Happy Coding Cheers!
来源:https://stackoverflow.com/questions/26360086/how-to-set-rating-bar-to-minimum-one-star