Thursday, March 1, 2012

Android rating example

This program is for illustrate the example of rating wizard




Step 1) Your main java file is here



package rating.bar;

import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;

public class RatingActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        callfun();
    }
   
    public void callfun()
    {
       final TextView tv=(TextView)findViewById(R.id.textView1);
       RatingBar rb=(RatingBar)findViewById(R.id.ratingBar1);
      
       rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
             
              public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
                     // TODO Auto-generated method stub
                    
                     tv.setText("The rate is :="+  String.valueOf(arg1));
                    
                    
              }
       });
      
      
       //tv.setText("Hello");
      
      
    }
   
   
}


Step 2) Your main.xml file content is here

<?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"
    android:weightSum="1">
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content"></RatingBar>
<TextView android:id="@+id/textView1" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0.15" android:layout_width="match_parent"></TextView>
</LinearLayout>



1 comment: