How to Add Android Ratingbar To Receive Feedback From Customers

How to Add Android Ratingbar Feature to Receive Feedbacks From Customers

0
Shares
How to Add Android Ratingbar Feature to Receive Feedbacks From Customers
4.3 (86%) 10 votes

You’ve seen rating bars, right? May be while shopping online on Amazon or in other apps. This Android ratingbar feature is used to give rating to apps, games, online products, services, and lots of other stuff. How does this feature help you ask? Well for starters, it allows app users to leave a feedback based on their experience on your Android app. This ultimately helps developers to identify where the app needs to be improved.

In today’s Android app tutorial, we’ll build a simple app to demonstrate the process of implementing Android ratingbar in an Android app.

Let’s Get Started

Create a new project under file menu, modify the project details and click on next button.

ssratingbardemo1

Choose Mini Support SDK for the project.

ssratingbardemo2

In the next tab, select Add No Activity and click on Finish button.

ssratingbardemo3

Now, create a XML file and use Custom View in it.

ssratingbardemo4

Next, create a class for MainActivity.

public class MainActivity extends AppCompatActivity{

    private RatingBar ratingBar;

private TextView tvRateCount,tvRateMessage;

private float ratedValue;

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    ratingBar = (RatingBar) findViewById(R.id.ratingBar);

    tvRateCount = (TextView) findViewById(R.id.tvRateCount);

    tvRateMessage = (TextView) findViewById(R.id.tvRateMessage);

    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override

        public void onRatingChanged(RatingBar ratingBar, float rating,

                                    boolean fromUser) {

            ratedValue = ratingBar.getRating();

            tvRateCount.setText("Your Rating : "

                    + ratedValue + "/5.");

            if(ratedValue<1){

                tvRateMessage.setText("ohh ho...");

            }else if(ratedValue<2){

                tvRateMessage.setText("Ok.");

            }else if(ratedValue<3){

                tvRateMessage.setText("Not bad.");

            }else if(ratedValue<4){

                tvRateMessage.setText("Nice");

            }else if(ratedValue<5){

                tvRateMessage.setText("Very Nice");

            }else if(ratedValue==5){

                tvRateMessage.setText("Thank you..!!!");

            }

        }

    });

}

}

Manage RatingBarChnageListener in Main Class.

ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

    @Override

    public void onRatingChanged(RatingBar ratingBar, float rating,

                                boolean fromUser) {

        ratedValue = ratingBar.getRating();

        tvRateCount.setText("Your Rating : "

                + ratedValue + "/5.");

        if(ratedValue<1){

            tvRateMessage.setText("ohh ho...");

        }else if(ratedValue<2){

            tvRateMessage.setText("Ok.");

        }else if(ratedValue<3){

            tvRateMessage.setText("Not bad.");

        }else if(ratedValue<4){

            tvRateMessage.setText("Nice");

        }else if(ratedValue<5){

            tvRateMessage.setText("Very Nice");

        }else if(ratedValue==5){

            tvRateMessage.setText("Thank you..!!!");

        }

    }

});

Now when you run the project, it’ll look like this.

ssratingbardemo5

Once you tap on any of the star, your rating will be submitted.

ssratingbardemo6

ssratingbardemo9

ssratingbardemo11

And done!

This was just a sample demo though. It is also possible to integrate a message box to receive a short message feedback along with the product rating in your product. This Android ratingbar is quite an important to understand the drawbacks of the app. So while building an Android app, consult with an Android app development company, and make sure to add this feature in your Android app.

Grab a free copy of Ratingbar Demo from Github.

 
0
Shares
 

Want to Develop Android App From Scratch? Contact Us Now

Get your free consultation now