Ratting bar Tutorial Android CodersArt

hello, friends
today we are going to learn about the very basic concept of Android.
we can see most apps had a rating bar or ratting activity for getting rates for our application from all users and using of it we can develop or modify our android application features as per user requirement . so lates take an example of ratting bar.

Main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#c2ffec"
    android:orientation="vertical">

    <RatingBar
        android:id="@+id/rateus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="250dp" />


    <Button
        android:id="@+id/btncheckrate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Check Rateing Value" />

</LinearLayout>

Main.java


public class Main extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final RatingBar rating=(RatingBar)findViewById(R.id.rateus);
        Button btncheckrate=(Button)findViewById(R.id.btncheckrate);
        btncheckrate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String rating_value=String.valueOf(rating.getRating());
                Toast.makeText(getApplicationContext(), rating_value, Toast.LENGTH_LONG).show();
            }
        });
    }
}


Comments