3

I have a code which has set of buttons listening for touch events.

for (int i = 0; i < mybtn.length; i++) {
    String btnid = "btn" + i;
    int resid = getResources().getIdentifier(btnid, "id", getPackageName());
    mybtn[i] = (Button) findViewById(resid);
    mybtn[i].setOnTouchListener(this);
}

But I am also using the TTS engine and I need to synchronize the speaking events with the touch events.

For that purpose I need to disable the touch listener for the buttons for some duration and then enable them after my work is done.

I want to write a method which can enable and disable touch events as per my requirements.

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
siva
  • 167
  • 1
  • 12

1 Answers1

4

To disable the Android touch listener you need to disable below properties...

 btn.setFocusable(false);

 btn.setClickable(false);

or

 btn.setEnabled(false);
Ola Ström
  • 4,136
  • 5
  • 22
  • 41
Maneesh
  • 6,098
  • 5
  • 36
  • 55
  • so i can reenable the functionality using btn.setEnabled(true); am i right?? – siva Mar 01 '12 at 09:53
  • Use `btn.setEnabled(false)` to temporarily disable it and then `btn.setEnabled(true)` to enable it again. Then use `btn.setOnTouchListner(null)` to remove it completely. – Ola Ström Jan 28 '22 at 10:48