Wednesday, December 26, 2012

Android - RatingBar Example


SIMPLE RATINGBAR

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
    
<RatingBar android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
    
                <TextView android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
    
</LinearLayout>

SOURCE CODE [RatingBarExample.java] is

package com.RatingBarExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.RatingBar.OnRatingBarChangeListener;

public class RatingBarExample extends Activity
{

                RatingBar ratingbar;
                TextView ratings;

                public void onCreate(Bundle savedInstanceState)
{
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                ratings = (TextView) findViewById(R.id.rating);
                                ratingbar = (RatingBar) findViewById(R.id.ratingbar);

                                ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
                                                public void onRatingChanged(RatingBar ratingBar, float rating,
                                                                                boolean fromUser)
{
                                                                // TODO Auto-generated method stub
                                                                ratings.setText("The Rating is " + rating);
                                                }
                                });
                }
}

The OUTPUT will be

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji3MM70Nof8IrwgU_ahUaTTCPbxLomnAYZ8m__m2t38u9krVKQl4aTucuutabFV1gDmP6JY8akWMzWxetZkFaXvuRyHXpWz9fm_1GJYlH42P6qVM6C2YSo0JIVoDvgEtyKF22YHa7qbwM/

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-zmuLUKq9wQluGl1XFPN8ayWtga_Uwwa3AB1_GrRDT6kxSK83RbAh0qTVrvxJihclAWkfo1sVaJ01Hd5OT54yrvka3W1P_79GTA-tOazjMAwUNaqAvE_BG-1ypkC207gwsqwAc9E1MyE/

No comments:

Post a Comment

Popular Posts