Home » » Android Simple RatingBar Example

Android Simple RatingBar Example

Written By MR HARI on Senin, 02 Mei 2011 | 22.43


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/AVvXsEiKXDHaKM0cE7yTGt-n48fYcEkFkGkwH9TDI6qnYI-QW_5QkrdFB5egUXrO82NWC8oCBMxTYswTnD6Uq3018XdL_Ro6MYWklYJP9limgOte-_jBj-OK4Yzh2eJVS5o3QMNkTx6FUoSWa3o/

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFPrSPZyiyRFqChBLgODdj_rk00SBgUJgUwtvUE-fR2flTUsvDlNlVaPND2YZqc9lqGvCKW6zf8RkGwjxBAxlvIWk1NCD-9jB7e6HlN0PRhx34qcgdeRYlLzGA0qTxiEbPaStGSbECrCA/
Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger