Saturday, September 8, 2012

Seek Bar In Android

This example shows how to Seek Bar in your application.
1.) Create a new project by File-> New -> Android Project name it SeekBarExample.
2.) Write following code into main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

    <SeekBar android:id="@+id/seek"
       android:secondaryProgress="75" />
    <TextView android:id="@+id/progress"
       android:layout_height="wrap_content" />
    <TextView android:id="@+id/tracking"
       android:layout_height="wrap_content" />
3.) Run for output.
1.) Create a project named SeekBarExample and set the information as stated in the image.
Build Target: Android 2.3.3
Application Name: SeekBarExample
Package Name: com.example
Activity Name: SeekBarExampleActivity
Min SDK Version: 10
2.) Open file and write following code there:
package com.example;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class SeekBarExampleActivity extends Activity implementsSeekBar.OnSeekBarChangeListener {
    SeekBar mSeekBar;
    TextView mProgressText;
    TextView mTrackingText;
    protected void onCreate(Bundle savedInstanceState) {
        mSeekBar = (SeekBar)findViewById(;
        mProgressText = (TextView)findViewById(;
        mTrackingText = (TextView)findViewById(;
    public void onProgressChanged(SeekBar seekBar, int progress, booleanfromTouch) {
        mProgressText.setText(progress + " " +
                "from touch" + "=" + fromTouch);
    public void onStartTrackingTouch(SeekBar seekBar) {
        mTrackingText.setText("Tracking on");
    public void onStopTrackingTouch(SeekBar seekBar) {
        mTrackingText.setText("Tracking off");
3.) Compile and build the project.

No comments:

Post a Comment