Sunday, 30 June 2013

Seek Bar Example

Main.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="10" />

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="" />

</LinearLayout>


Main Java File

package com.example.seekbar;

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


public class MainActivity extends Activity implements OnSeekBarChangeListener{

private SeekBar mSeekBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

       mSeekBar = (SeekBar) findViewById(R.id.seek_bar);
       mSeekBar.setOnSeekBarChangeListener(this);
   }

   @Override
   public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
       Toast.makeText(MainActivity.this, "Seekbar Value : " + progress, Toast.LENGTH_SHORT).show();
   }

   @Override
   public void onStartTrackingTouch(SeekBar seekBar) {
       Toast.makeText(MainActivity.this, "Started Tracking Seekbar", Toast.LENGTH_SHORT).show();
   }

   @Override
   public void onStopTrackingTouch(SeekBar seekBar) {
       mSeekBar.setSecondaryProgress(seekBar.getProgress());
       Toast.makeText(MainActivity.this, "Stopped Tracking Seekbar", Toast.LENGTH_SHORT).show();
   }
}



No comments:

Post a Comment