TechAmongus:App Review,Technology,How-To,Android

Android Create SeekBar in Activity - TechAmongus

Android Create SeekBar in Activity

SeekBar is just progress bar with draggable thumb .It is used to set value .Position of Thumb will decide the value .Best Example of SeekBar is volume set ,Brightness of screen etc .

In Android , SeekBar is class and inherit Progress Bar

First define SeekBar in your main_activity layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="#FFFFFF"
              android:orientation="vertical">

  <SeekBar                    android:id="@+id/seekBar"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="20dp"
                    android:layout_weight=".7"
                    android:max="31"
                    android:maxHeight="3dp"
                    android:thumb="@drawable/thumb" />


</LinearLayout>

Second declare Seekbar in MainActivity.java

public class MainActivity extends Activity implements OnSeekBarChangeListener{

    // declare text objects variables
    private SeekBar seekbar; 
    int seekValue

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // load the layout
        setContentView(R.layout.filters);   

        seekbar = (SeekBar)findViewById(R.id.seekBar); // make seekbar object
        seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                
               value=seekBar.getProgress();
                seekBar.setMax(100);
            }
        });
    }

    
}

No comments

Powered by Blogger.