<SeekBar android:id="@+id/seekBar1" android:layout_width="match_parent" android:layout_height="wrap_content" />
<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" > <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="112dp" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/seekBar1" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="23dp" android:text="TextView" /> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.SeekBar; import android.widget.TextView; import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // seekBar1 final SeekBar seek_Bar = (SeekBar)findViewById(R.id.seekBar1); // textView1 final TextView txtView1 = (TextView)findViewById(R.id.textView1); // textView2 final TextView txtView2 = (TextView)findViewById(R.id.textView2); seek_Bar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seek_Bar, int progress, boolean fromUser) { // TODO Auto-generated method stub txtView1.setText("SeekBar value is "+progress); } public void onStartTrackingTouch(SeekBar seek_Bar) { // TODO Auto-generated method stub txtView2.setText("SeekBar is Starting"); } public void onStopTrackingTouch(SeekBar seek_Bar) { // TODO Auto-generated method stub txtView2.setText("SeekBar is Stop"); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท