Suppose, for example, that I use a single if statement to account for ten different possible button clicks that send an event value to an event listener:
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; }
Would it be more efficient to classify them? let's say ... one onClick event for traps and one for bass and one for hi hats, so when you click the button, the program should not check every if statement, only the one inside the listener for the fired event?