Reputation: 695
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!!"
Upvotes: 6
Views: 5275
Reputation: 984
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;
}
}
Upvotes: 8
Reputation: 831
Implement the onRatingBarChangeListener
and place the intent for the new activity inside it:
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// place intent for new activity
}
});
Use the RatingBar.getRating()
method to get the current rating. If it returns zero, then prompt the user to rate your app with a toast.
You can more about Rating Bar and its methods here.
Upvotes: 0