Android Rating Bar

Android Development

Android Rating Bar :-


⇛ layout > .xml file :

<?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=".First"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pleaase give us rating :"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#000"
android:padding="20sp"/>
<RatingBar
android:id="@+id/Idratingbar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"/>
<Button
android:id="@+id/Idbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="Submit"
android:textSize="20sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#0733c6"
android:padding="10dp"/>
<TextView
android:id="@+id/Idtextview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textStyle="bold"
android:textSize="20sp"
android:textAllCaps="false"
android:padding="10dp"
android:textAlignment="center"/>
</LinearLayout>

⇛ java file :

package com.example.dell.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;
public class First extends AppCompatActivity {
private RatingBar ratingBar;
private TextView textView2;
private Button btn;
private float rating;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
ratingBar = (RatingBar) findViewById(R.id.Idratingbar1);
textView2 = (TextView) findViewById(R.id.Idtextview2);
btn = (Button) findViewById(R.id.Idbutton1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rating = ratingBar.getRating();
if(rating<2){
textView2.setText("Rating : "+rating+"\nIt it that worse ?");
}else if (rating<=3 && rating>=2){
textView2.setText("Rating :"+rating+"\nWe will try to the better .");
}else if (rating>3 && rating<=4){
textView2.setText("Rating :"+rating+"\nThat means you havinng good time here :)");
}else if (rating>4){
textView2.setText("Rating :"+rating+"\nWOW ! We will keep up the good work .");
}
}
});
}
}

No comments

Powered by Blogger.