Does "While-Clicking" event handler exist in Android Studio? -


i want call function while user pressing on button, infinite loop long button pressed, break once user releases button. can looking button-while-clicking event handler

i sure such event handler exists in maybe ides. how can approach in android studio?

providing example sample task highly appreciated:

while-clicking:

    // button clicking     int = 0;     btn.setonclicklistener(             new button.onclicklistener() {                 public void onclick(view v) {                     textone.settext("clicking" + i++);                 }//onclick             }//onclicklistener     );//setonclicklistener 

when released:

    // button released     btn.setonclicklistener(             new button.onclicklistener() {                 public void onclick(view v) {                     textone.settext("released");                 }//onclick             }//onclicklistener     );//setonclicklistener 

..

edit: solution seemed ontouchlistener() event handler , had import android.view.motionevent; use it.

you looking ontouchlistener -

button.setontouchlistener(new ontouchlistener() {              @override             public boolean ontouch(view v, motionevent event) {                 if (event.getaction() == motionevent.action_down) {                     //button pressed                       textone.settext("clicking");                            return true;                 }                  else if (event.getaction() == motionevent.action_up) {                     //button released                     textone.settext("released");                     return true;                  }                 return false;             }         }); 

motionevent.action_down generated when user touches button , motionevent.action_up generated when user removes touch button.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -