【发布时间】:2015-08-22 10:37:19
【问题描述】:
相对而言,我是 Java/Android 编程的新手/初学者。我一直在尝试这样做,所以当我在应用程序中按下给定按钮时,它会产生 DTMF 音,但是当我尝试使用 setOnTouchListener 时,Android Studio 会向我显示该错误。它还给了我一个 MotionEvent 错误,指出 Expression expected
以下是代码的重要部分:
boolean pressedCCW = false;
class SendCCWTone extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... arg0){
ToneGenerator toneGen;
toneGen = new ToneGenerator(AudioManager.STREAM_DTMF,100);
while(pressedCCW){
toneGen.startTone(ToneGenerator.TONE_DTMF_1);
}
toneGen.stopTone();
toneGen.release();
createLog("CCW");
return null;
}
}
final Button buttonCCW = (Button) findViewById(R.id.counter_clockwise);
buttonCCW.setOnTouchListener(new View.OnTouchListener(){// Where the error is
@Override
public boolean onTouch(View v, MotionEvent event){// Where the other error is located
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if(pressedCCW == false){
pressedCCW = true;
new SendCCWTone().execute();
}
break;
case MotionEvent.ACTION_UP:
pressedCCW = false;
}
return true;
}
});
【问题讨论】:
标签: java android android-studio android-asynctask android-button