我正在尝试同时处理 android 中的两个 seekBar。我检查了很多示例,但所有这些示例都旨在处理按钮或类似视图。当我尝试执行这些示例在我的 seekBar 项目中描述的相同过程时,它不起作用。当我按下第一个 seekBar 时,我想显示一个具有特定值的 textView,而当我按下第二个 seekBar 时,另一个 textView 显示另一个特定值这是我的代码:
public class Bluetoo extends Activity {
private Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.botones);
setViews();
handler.postDelayed(mUpdateUITimerTask, 100);
}
private final Runnable mUpdateUITimerTask = new Runnable() {
public void run() {
// do whatever you want to change here, like:
updateTextField();
}
};
private void updateTextField() {
mTitle=(TextView) findViewById(R.id.textView1);
mTitle2=(TextView) findViewById(R.id.textView2);
mTitle.setText(sqText1);
mTitle2.setText(sqText2);
handler.post(mUpdateUITimerTask);
}
private void setViews() {
vSeekBar1 = (VerticalSeekBar)findViewById(R.id.SeekBar01);
vSeekBar1.setMax(100);
vSeekBar1.setProgress(50);
vSeekBar1.setOnTouchListener(new TouchListener());
vSeekBar2 = (VerticalSeekBar)findViewById(R.id.SeekBar02);
vSeekBar2.setMax(100);
vSeekBar2.setProgress(50);
vSeekBar2.setOnTouchListener(new TouchListener());
}
private class TouchListener implements OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
switch(v.getId()) {
case R.id.SeekBar01:
sqText1=("first");//actually this part is more complex but
//I did not include it here
break;
case R.id.SeekBar02:
sqText2=("second");//actually this part is more complex but
//I did not include it here
}
}
else if(event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
switch(v.getId()) {
case R.id.SeekBar01:
sqText1=("second first");//actually this part is more complex but
//I did not include it here
break;
case R.id.SeekBar02:
sqText2=("second second");//actually this part is more complex but
//I did not include it here
break;
}
}
}
}
}