ProgressBar & SeekBar

ProgressBar, SeekBar

/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/TextView01" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<ProgressBar android:id="@+id/ProgressBar01"
		android:layout_width="fill_parent" android:layout_height="wrap_content"
		style="?android:attr/progressBarStyleHorizontal" />
	<SeekBar android:id="@+id/SeekBar01" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:thumb="@drawable/icon" />
</LinearLayout>

Activity File

package com.androidwork.progressbardemo;

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

public class ProgressBarDemoActivity 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);
		setProgressBarIndeterminateVisibility(true);
		setProgressBarVisibility(true);
		setProgress(5000);

		ProgressBar pb = (ProgressBar) findViewById(R.id.ProgressBar01);
		pb.setProgress(50);

		SeekBar sb = (SeekBar) findViewById(R.id.SeekBar01);
		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 tv = (TextView) findViewById(R.id.TextView01);
				tv.setText("Progress is: " + progress);
				seekBar.setSecondaryProgress((seekBar.getMax() + progress) / 2);
			}

		});

	}
}

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