Android:一次处理两个seekBar的多点触控事件

时间:2013-07-01 01:42:50

标签: handle seekbar

我正在尝试同时在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;
            }
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

vSeekBar1.setOnSeekBarChangeListener(this);
vSeekBar2.setOnSeekBarChangeListener(this);

@Override
public void onProgressChanged(SeekBar v, int progress, boolean fromUser) {

    switch(v.getId())
    {
    case R.id.vSeekBar1 :
        v1 = (TextView)findViewById(R.id.v1_progress);
        v.setProgress(progress);
        v1.setText("text/result you want displayed for vSeekBar1"); 
        break;
    case R.id.vSeekBar2:
        v2= (TextView)findViewById(R.id.v2_progress);
        v.setProgress(progress);
        v2.setText("text/result you want displayed for vSeekBar2");
        break;
    }        
}