---
title: "Android  Rating bar"  
description: "Rating bar is a control which provides a user interface to give feedback about the application. It always returns value in floating point"  
author: "Nitish Kesarwani"  
published: 2017-12-28  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/12746/android-rating-bar  
category: "android apps"  
tags: ["android", "java", "onclicklistener"]  
reading_time: 4 minutes  

---

# Android  Rating bar

Rating bar is a control which provides a [user interface](https://www.mindstick.com/blog/302016/what-is-user-interface-and-what-are-its-benefits) to give feedback about the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android). It always returns value in floating point. I am using Rating Bar, Button and [Text view](https://www.mindstick.com/forum/33384/detail-text-view-of-cell-not-showing) controls to get the feedback when the [user clicks](https://answers.mindstick.com/qa/34556/if-a-user-clicks-all-the-google-ads-on-my-site-is-it-foul) on the button. ratingbar() and [onClickListener](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach) are used to invoke the users' feedback.

##### Attributes

**o android:numStars:** This [attribute](https://www.mindstick.com/blog/61/ado-dot-net-object-model-and-attributes) displays the number of stars for user feedback

**o android:rating****:** By this method, you can set rating point for the user

**o android:isIndicator:** It checks whether rating bar has indicator state

**o android:stepSize:** It is used to set the number of step size increment in a value of rating.

##### Methods

**o getOnRatingBarChangeListener()****:** It is a [callback method](https://www.mindstick.com/forum/215/callback-method-in-jquery), which is called when the users give rating to the application

**o setOnRatingBarChangeListenter():** This method sets the listener for star bars ,when user selects the number of stars.

**o getnumStars():** We get the number of stars shown in devices by using this method

**o setnumStars():** we can set the number of stars displayed on screens.

**o getisIndicator():** This method allows users to not change the rating bar value

**o setisIndicator():** If its value is true, users cannot change the value of stars.

**o setMax():** It sets the maximum limit of rating bar stars values

**o getRating()****:** It returns the number of a rating given by users.

**o setRating():** In this method, we assign the value of stars is filled

**o setStepSize():** We can set the number of stars value incremented on users feedback

**o getStepSize()****:** We get the response of each value of star on the basis of selection of stars

\

###### Android_Manifest.xml

```
    <applicat<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mapsample.msclient009.ratingbar">

ion
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
```

###### Main_Activity.xml

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mapsample.msclient009.ratingbar.MainActivity"
    android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#199119"
        android:gravity="center"
        android:text="Ths is Rating Bar"
        android:textColor="#F9F9F9"
        android:textSize="20dp" />

    <RatingBar
        android:id="@+id/ratebar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_below="@+id/tv"
        android:layout_centerHorizontal="true"
        android:layout_weight="1" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/btn"
        android:layout_marginTop="0dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_below="@+id/ratebar"
        android:text="Rate it Now"
        />
    </LinearLayout>
</LinearLayout>
```

\

###### Main_Activity.java

```
package com.mapsample.msclient009.ratingbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
RatingBar rb;
Button btn;
TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main );
        ratingStar();
    }
    public void ratingStar()
    { rb =(RatingBar)findViewById ( R.id.ratebar );
      btn =(Button)findViewById ( R.id.btn );
      tv =(TextView)findViewById ( R.id.tv );
      btn.setOnClickListener ( new View.OnClickListener ( ) {
          @Override
          public void onClick(View v) {
            String rateNumber =String.valueOf (rb.getRating ());
              Toast.makeText ( getApplicationContext (),"You have rated"+rateNumber,Toast.LENGTH_LONG ).show ();
              double value = Double.valueOf ( Double.valueOf (rateNumber ) );
              if(value>3 && value<=5)
              {
                  Toast.makeText ( getApplicationContext (),"This app is a good",Toast.LENGTH_LONG ).show ();

              } else {Toast.makeText ( getApplicationContext (),"This app is not a good",Toast.LENGTH_LONG ).show ();}
          }
      } );

    }
}
```

##### Launch Your APP

![Android  Rating bar](https://www.mindstick.com/mindstickarticle/1a7720cf-4443-4fc1-9733-8652167d2d56/images/ed2759b4-7a69-4dc9-95b3-9778007c6127.png)![Android  Rating bar](https://www.mindstick.com/mindstickarticle/1a7720cf-4443-4fc1-9733-8652167d2d56/images/6cdece21-a4d7-4b3e-a49a-73e57f32469f.png)\

---

Original Source: https://www.mindstick.com/articles/12746/android-rating-bar

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
