Seek Bar : A
SeekBar is an extension of ProgressBar that adds a draggable thumb. The user
can touch the thumb and drag left or right to set the current progress level or
use the arrow keys. Placing focusable widgets to the left or right of a SeekBar
is discouraged.
Clients of the SeekBar can attach a
SeekBar.OnSeekBarChangeListener to be notified of the user's actions.
SeekBar.OnSeekBarChangeListener
:
A callback that notifies clients when the progress level has
been changed. This includes changes that were initiated by the user through a
touch gesture or arrow key/trackball as well as changes that were initiated
programmatically.
Methods:
onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) : Notification that the progress level has changed.
onStartTrackingTouch(SeekBar seekBar): Notification that the
user has started a touch gesture.
onStopTrackingTouch(SeekBar seekBar) :Notification that the
user has finished a touch gesture.
MainActivity.java :
public class MainActivity extends Activity {
SeekBar seek;
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO Auto-generated
method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seek = (SeekBar)
findViewById(R.id.seekBar1);
seek.setOnSeekBarChangeListener(new
OnSeekBarChangeListener() {
@Override
public void
onStopTrackingTouch(SeekBar seek) {
Toast.makeText(MainActivity.this, "App is
loaded", Toast.LENGTH_LONG).show();
}
@Override
public void
onStartTrackingTouch(SeekBar seek) {
Toast.makeText(MainActivity.this, "App will be
loaded soon", Toast.LENGTH_LONG).show();
}
@Override
public void
onProgressChanged(SeekBar seek, int progress, boolean fromUser) {
Toast.makeText(MainActivity.this, "Seekbar Value
: "
+ progress, 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;
}
}
In 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_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="107dp" />
</RelativeLayout>
No comments:
Post a Comment