RatingBar

ProgressBar, SeekBar, RatingBar

/res/layout/main.xml file

<?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:id="@+id/seek_text" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<TextView android:id="@+id/rating_text" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<ProgressBar android:id="@+id/progress_bar01"
		android:layout_width="wrap_content" android:layout_height="wrap_content" />
	<ProgressBar android:id="@+id/progress_bar02"
		style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:max="100" />
	<SeekBar android:id="@+id/seekbar1" android:layout_height="wrap_content"
		android:layout_width="240px" />
	<ProgressBar android:id="@+id/progress_bar"
		style="?android:attr/progressBarStyleSmall" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:max="100" />
	<SeekBar android:id="@+id/seekbar1" android:layout_height="wrap_content"
		android:layout_width="240px" android:max="500" />
	<ProgressBar android:id="@+id/progress_bar"
		style="?android:attr/progressBarStyleSmall" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:max="100" />
	<SeekBar android:id="@+id/seekbar1" android:layout_height="wrap_content"
		android:layout_width="240px" android:max="500" android:thumb="@drawable/icon" />
	<RatingBar android:id="@+id/ratebar1" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:numStars="4"
		android:stepSize="0.40" />
</LinearLayout>

Activity file


package com.androidwork.progressseekratinbardemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;

public class ProgressSeekRatingBarDemoActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		requestWindowFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.main);

		setContentView(R.layout.main);
		// setContentView(R.layout.indicators);
		setProgressBarIndeterminateVisibility(true);
		setProgressBarVisibility(true);
		setProgress(5000);
		ProgressBar pb = (ProgressBar) findViewById(R.id.progress_bar02);
		pb.setProgress(50);
		//

		SeekBar seek = (SeekBar) findViewById(R.id.seekbar1);
		seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				((TextView) findViewById(R.id.seek_text)).setText("Value: "
						+ progress);
				seekBar.setSecondaryProgress((progress + seekBar.getMax()) / 2);

			}
		});
		RatingBar rate = (RatingBar) findViewById(R.id.ratebar1);
		rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

			public void onRatingChanged(RatingBar ratingBar, float rating,
					boolean fromUser) {
				// TODO Auto-generated method stub
				((TextView) findViewById(R.id.rating_text)).setText("Rating: "
						+ rating);

			}
		});
		SeekBar sb = (SeekBar) findViewById(R.id.seekbar1);
		sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				((TextView) findViewById(R.id.seek_text))
						.setText("Progress is : " + progress);
				seekBar.setSecondaryProgress(((seekBar.getMax() - progress) / 2)
						+ progress);
			}
		});

		RatingBar rb = (RatingBar) findViewById(R.id.ratebar1);
		rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

			public void onRatingChanged(RatingBar ratingBar, float rating,
					boolean fromUser) {
				// TODO Auto-generated method stub
				((TextView) findViewById(R.id.seek_text))
						.setText("Rating is : " + rating);
			}
		});

	}
}

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s