Home > Android > Android Ratingbar | Source Code

Android Ratingbar | Source Code

Android Ratingbar

 Android Ratingbar 

Android Ratingbar | Source code

Android Ratingbar   Android Ratingbar

Java Code(RatingAct )

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView;

public class RatingAct extends Activity {
TextView tv;
RatingBar rb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating);

tv = (TextView)findViewById(R.id.textView);
rb = (RatingBar)findViewById(R.id.rb1);

rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener()
{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
tv.setText(“”+rating);
}
});

}
}


Layout XML Code(activity_rating))

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.RatingAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:layout_gravity=”center”
android:textStyle=”bold”
android:text=”@string/ratingtext”
android:layout_marginBottom=”120dp” />

<RatingBar
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/rb1″
android:layout_gravity=”center”
android:layout_alignParentTop=”true”
android:layout_centerHorizontal=”true” />

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textAppearance=”?android:attr/textAppearanceLarge”
android:text=” “
android:layout_gravity=”center”
android:id=”@+id/textView”
android:layout_below=”@+id/rb1″
android:layout_centerHorizontal=”true”
android:layout_marginTop=”25dp”
android:layout_marginBottom=”120dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

Output

Android Ratingbar   Android Ratingbar

Download Source code

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

android interview questions for freshers


Recent   

Android Ratingbar

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »