假设我使用一个语句, 说明十种可能不同的按键, 将事件值发送给活动听众:
public boolean onTouch(int v) { //this is my only listener for all ten buttons
if(event.getAction() == MotionEvent.ACTION_DOWN){
if(v==button_one){pool.play(bass1, 1f,1f, 1, 0, 1f);}
if(v==button_two){pool.play(bass2, 1f,1f, 1, 0, 1f);}
if(v==button_three){pool.play(bass3, 1f,1f, 1, 0, 1f);}
if(v==button_four){pool.play(snare1, 1f,1f, 1, 0, 1f);}
if(v==button_five){pool.play(snare2, 1f,1f, 1, 0, 1f);}
if(v==button_six){pool.play(snare3, 1f,1f, 1, 0, 1f);}
if(v==button_seven){pool.play(hh1, 1f,1f, 1, 0, 1f);}
if(v==button_eight){pool.play(hh2, 1f,1f, 1, 0, 1f);}
}
return false;
}
将这些分类是否更有效率?比如... 一个点击事件是圈圈的,一个点击事件是低音的,一个点击事件是低音的,一个点击事件是hi hats的,这样当按下按钮时,程序就不必在每次声明中计数,如果声明的话,只有一个听众在听发射事件吗?