我正在做一个fife应用程序。我的五官有 6 个孔,我认为它们是 6 个纽扣。如您所知,如果您一次握住一个、两个或多个孔(此处为按钮),则在法夫斯中会有所不同。我是android新手,我该如何管理它?例如,我想这样做:
如果同时触摸 button1 和 button2:如果同时触摸
button6 和 button2,则播放 sound1:
如果同时触摸 button1 和 button2 和 buuton3,则播放 sound2:播放 sound3
。
.
.
最后我使用了这个技巧:
one.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is1t = true;
soundtoplay();
one.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is1t = false;
soundtoplay();
one.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
two.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is2t = true;
soundtoplay();
two.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is2t = false;
soundtoplay();
two.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
three.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is3t = true;
soundtoplay();
three.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is3t = false;
soundtoplay();
three.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
...
public void soundtoplay(){
if(is1t == true && is2t == false && is3t == false && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.b);
mp.start();
}else if(is1t == true && is2t == true && is3t == false && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.a);
mp.start();
}else if(is1t == true && is2t == true && is3t == true && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.g1);
mp.start();
}else if ...