Android Example of SeekBar

      No Comments on Android Example of SeekBar

activity_main.xml

Drag the seek bar from the palette

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="48dp" />

</RelativeLayout>

MAinActivity.java

package com.example.seekbar;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.*;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class MainActivity extends Activity implements OnSeekBarChangeListener

{
	SeekBar s1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	s1=(SeekBar)findViewById(R.id.seekBar1);
	
	s1.setOnSeekBarChangeListener(this);
	}
	
	@Override
	public void onProgressChanged(SeekBar s1,int i1,boolean fromUSer)
	{
	Toast.makeText(getApplicationContext(),"SeekBar Progress:- "+i1,Toast.LENGTH_SHORT).show();	
	}
	
	
	@Override
	public void onStartTrackingTouch(SeekBar arg0) 
	{
		Toast.makeText(getApplicationContext(),"SeekBar Started ",Toast.LENGTH_SHORT).show();	
		
	}

	@Override
	public void onStopTrackingTouch(SeekBar arg0) 
	{
		Toast.makeText(getApplicationContext(),"SeekBar stoped",Toast.LENGTH_SHORT).show();	
		
	}

}

OUTPUT:-

Leave a Reply

Your email address will not be published. Required fields are marked *