Android SeekBar Example


What is Android SeekBar- 
         
       Android SeekBar is a sort of ProgressBar with draggable thumb. The end client can drag the thum left and right to move the advancement of tune, document download and so forth.

The SeekBar.OnSeekBarChangeListener interface gives techniques to perform actually taking care of for look for bar.

Android SeekBar and RatingBar classes are the sub classes of AbsSeekBar

Android SeekBar Example

activity_main.xml

Drag the look for bar from the pallete, now activity_main.xml will resemble this:

File: activity_main.xml
<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" >  
  
    <SeekBar  
        android:id="@+id/seekBar1"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:layout_alignParentTop="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="39dp" />  
  
</RelativeLayout>  


Activity class

We should see the Activity class showing look for bar and performing occasion taking care of.

File: MainActivity.java
package com.dheeruapps.seekbar;  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.widget.SeekBar;  
import android.widget.SeekBar.OnSeekBarChangeListener;  
import android.widget.Toast;  
public class MainActivity extends Activity implements OnSeekBarChangeListener{  
    SeekBar seekBar1;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
          
        seekBar1=(SeekBar)findViewById(R.id.seekBar1);  
        seekBar1.setOnSeekBarChangeListener(this);  
    }  
    @Override  
    public void onProgressChanged(SeekBar seekBar, int progress,  
            boolean fromUser) {  
        Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();  
    }  
    @Override  
    public void onStartTrackingTouch(SeekBar seekBar) {  
        Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();  
    }  
    @Override  
    public void onStopTrackingTouch(SeekBar seekBar) {  
        Toast.makeText(getApplicationContext(),"seekbar touch stopped!", Toast.LENGTH_SHORT).show();  
    }  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.main, menu);  
        return true;  
    }  
}  

Output: 





0 comments:

Post a Comment

My Instagram