控件:拖动条 --- SeekBar(事件处理)

View Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation
="vertical"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent">
<SeekBar
android:id="@+id/seekbar"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content" />
<TextView
android:id="@+id/text"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"/>
</LinearLayout>
View Code
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.SeekBar;
import android.widget.TextView;

public class MySeekBarDemo extends Activity {
private SeekBar seekbar = null;
private TextView text = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
// 取得组件
this.seekbar = (SeekBar) super.findViewById(R.id.seekbar);
// 取得组件
this.text = (TextView) super.findViewById(R.id.text);
// 文本组件的内容可以滚动
this.text.setMovementMethod(ScrollingMovementMethod.getInstance());
this.seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl());
}

private class OnSeekBarChangeListenerImpl implements SeekBar.OnSeekBarChangeListener {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
MySeekBarDemo.this.text.append("*** 开始拖动,当前值:"
+ seekBar.getProgress() + "\n");
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
MySeekBarDemo.this.text.append("*** 正在拖动,当前值:"
+ seekBar.getProgress() + "\n");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
MySeekBarDemo.this.text.append("*** 停止拖动,当前值:"
+ seekBar.getProgress() + "\n");
}

}
}

 



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2012-03-04 12:15  大米稀饭  阅读(549)  评论(0编辑  收藏  举报