0

I have a button (button1) and two sound (sound1, sound2), I want to implement a gesture to this button. if Button1 is clicked, then the sound is sound1 but if Button1 is touched by the gesture, the sound is sound2. to handle the sound, I use a SoundManager class. to handle touch I use multitouch class.

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();
    }

}

Thank you so much

qboel
  • 1
  • 2
  • your code looks fine ....what's the problem that you are facing? – karn Oct 11 '12 at 03:15
  • have a look on this question http://stackoverflow.com/questions/937313/android-basic-gesture-detection – BBdev Oct 11 '12 at 03:55
  • the problem is I want to add gesture on button1 to call sound2. if i use the code above, I can only call sound1 by the click. I want, when I click button1 I want the sound is sound1 but when I touched button1 using gesture, then the sound is sound2. --Using Google Translate-- – qboel Oct 11 '12 at 05:06

3 Answers3

0

There is no big difference between click and touch. But if you want to implement both, you have to make a trick to make it work.

For the System it is hard to decide laying the finger on a button, if you want to "click" or "touch" it. To controll this, you can get the time, the button is clicked/touched/whatever...

for example: If you click/touch/whatever a Button you start counting, if you stopped clicking/touching/whateevring you stopped the countig. After that its easy: if(time < 1s) else

Beware, that it would be a good idea to have a Click-Listener and TouchListener with the same code in it and just decide, using the counting stuff.

I've implemeted it already at it works perfectly!

Yvonne Marggraf
  • 398
  • 2
  • 5
  • 19
  • in ouTouch you can handle all other events fling scroll or single tap double tap.. But onClick only handle click – Zar E Ahmer Sep 15 '16 at 06:23
0

You can for exemple use a GestureListener (https://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html#5307216038506006379) and handle the differents events or type of gesture for your button (touch, tap, swipe...)

-1

dynamically creating button would cause problems.but if make the buttons in you xml file and then set on