How to set rating bar to minimum one star?

此生再无相见时 提交于 2020-01-03 07:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!