我有兩個按鈕,如果按下它們會發出聲音。我想同時按兩個鍵同時聽到兩個聲音。到目前爲止:使用兩個按鈕的多點觸控問題:即使按兩個不同的按鈕時也總是得到相同的按鈕,爲什麼?
@覆蓋 //處理導航箭頭 公共布爾onTouch(視圖V,MotionEvent事件){
int action = event.getActionMasked();
switch (action){
case MotionEvent.ACTION_DOWN:
switch (v.getId()) { // Which button?
case R.id.cnotebutton: // The upArrow
Log.i("C", "C");
// mSoundPool.stop(mStream1);
//mStream1= mSoundPool.play(mSoundPoolMap.get(1), streamVolume, streamVolume, 1,0, 1f);
break;
case R.id.dnotebutton: // The downArrow
Log.i("D", "D");
// mSoundPool.stop(mStream2);
//mStream2= mSoundPool.play(mSoundPoolMap.get(2), streamVolume, streamVolume, 1,0, 1f);
break;
default:
}
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
switch (v.getId()) { // Which button?
case R.id.cnotebutton: // The upArrow
Log.i("C", "C");
// mSoundPool.stop(mStream1);
//mStream1= mSoundPool.play(mSoundPoolMap.get(1), streamVolume, streamVolume, 1,0, 1f);
break;
case R.id.dnotebutton: // The downArrow
Log.i("D", "D");
// mSoundPool.stop(mStream2);
//mStream2= mSoundPool.play(mSoundPoolMap.get(2), streamVolume, streamVolume, 1,0, 1f);
break;
default:
}
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
break;
default:
}
return true;
}
它不工作的韻味。我應該如何解決這個問題?另一個問題,如果我在屏幕上移動手指我想按下按鈕,當我的手指到達按鈕而沒有提起它。 ACTION_MOVE也可以工作。對不起,這個愚蠢的問題我非常喜歡這個領域的初學者。
UPDATE
有了這個代碼,它檢測到的多點觸控,但我得到了總有兩個相同的日誌,如果我感動總是相同的按鈕與兩個我的手指。所以,即使我同時按下兩個按鈕,我會得到一個日誌「C」和另一個「C」,這是錯誤的,我應該得到C和D.
感謝您的提前!
不,我不使用surfaceview,我應該?爲什麼會更好?如果我只是爲每個按鈕設置onClickListener,它仍然不會工作。 – erdomester
我檢查了我製作的遊戲的源代碼,並確實使用了onTouchListener。如果你處理了這個事件,也許你應該返回True而不是假? –
沒有改變:S仍然播放它首先檢測到的聲音。 –