我有一个按钮(button1)和两个声音(sound1,sound2),我想实现这个按钮的一个手势。如果单击Button1,则声音是声音1,但如果按钮1被手势触摸,则声音是声音2。处理声音,我使用SoundManager类。处理触摸我使用多点触摸类。如何在android上实现一个按钮的手势?
public class MyActivity extends MultiTouch {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
SoundManager.getInstance();
SoundManager.initSounds(this);
SoundManager.loadSounds();
Button Button1 = (Button)findViewById(R.id.button1);
Button1.setOnTouchListener(this);
Button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SoundManager.playSound(1, 1);
}
});
}
public void onDestroy()
{
super.onDestroy();
SoundManager.cleanup();
}
}
谢谢你这么多
你的代码看起来很好....你面临的问题是什么? – karn
看看这个问题http://stackoverflow.com/questions/937313/android-basic-gesture-detection – BBdev
问题是我想在button1上添加手势来调用sound2。如果我使用上面的代码,我只能通过点击来调用sound1。我想,当我点击button1时,我希望声音是声音1,但是当我用手势触摸button1时,声音就是sound2。 - 使用谷歌翻译 - – qboel