0

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

}

4

1 回答 1

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;
    }        
}
于 2013-10-13T00:56:21.223 回答