Here is a simple example to show how to use seek Bar in android.
Create a new project and place this code in it.
The main.xml file
The strings.xml file.
Create a new project and place this code in it.
package com.coderzheaven;<span class="IL_AD" id="IL_AD3">import</span> android.app.Activity;import android.os.Bundle;import android.widget.SeekBar;import android.widget.TextView;public <span class="IL_AD" id="IL_AD4">class</span> SeekBarDemo extends Activity implements SeekBar.OnSeekBarChangeListener { SeekBar mSeekBar; TextView mProgressText; TextView mTrackingText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mSeekBar = (SeekBar)findViewById(R.id.<span class="IL_AD" id="IL_AD5">seek</span>); mSeekBar.setOnSeekBarChangeListener(this); mProgressText = (TextView)findViewById(R.id.progress); mTrackingText = (TextView)findViewById(R.id.<span class="IL_AD" id="IL_AD1">tracking</span>); } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { mProgressText.setText(progress + " " + getString(R.<span class="IL_AD" id="IL_AD9">string</span>.seekbar_from_touch) + "=" + fromTouch); } public void onStartTrackingTouch(SeekBar seekBar) { mTrackingText.setText(getString(R.string.seekbar_tracking_on)); } public void onStopTrackingTouch(SeekBar seekBar) { mTrackingText.setText(getString(R.string.seekbar_tracking_off)); }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:<span class="IL_AD" id="IL_AD6">orientation</span>="<span class="IL_AD" id="IL_AD7">vertical</span>" android:layout_width="fill_parent" android:layout_height="fill_parent"> <SeekBar android:id="@+id/seek" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="50" android:secondaryProgress="75" /> <TextView android:id="@+id/progress" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/tracking" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout> |
1
2
3
4
5
6
7
| <?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">SeekBarDemo</string> <string name="seekbar_tracking_on">Tracking on</string> <string name="seekbar_tracking_off">Tracking off</string> <string name="seekbar_from_touch">from touch</string></resources> |
No comments:
Post a Comment