Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a rating bar is has been rated or not in android?

I have a rating bar in my app and I want to check if the user has rated on the rating bar or not. If it been has rated by the user then , an intent takes you to the next screen and if he has not rated then there is toast message which says "Please rate us!!"

like image 878
Prateek Mahesh Avatar asked Jul 17 '16 03:07

Prateek Mahesh


1 Answers

First, you have to set android:rating="0.0" to your RatingBar in xml. Then on button click check,

RatingBar ratingbar = (RatingBar)findViewById(R.id.ratingBar);
@Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ratingBar:
                 if(ratingbar.getRating() == 0.0){

                    //set what you want
                     }else{

                    //give error if ratingbar not changed
                     }
            break;
    }
}
like image 72
Vishal Jadav Avatar answered Sep 25 '22 21:09

Vishal Jadav