Android data binding view.onTouchListener -


android in data binding there

<button android:onclick="@{handler.somebuttonclick()}"/> 

and in handler class listener how like:

public view.onclicklistener somebuttonclick() {         return new view.onclicklistener() {             @override             public void onclick(view view) {              }         };     } 

i want implement ontouchlistener button know when button pressed , when released

like:

// check if button pressed if (event.getaction() == motionevent.action_down){      //do thing           }// check if button released else if (event.getaction() == motionevent.action_up) {     //do thing                      } 

is there possible way accomplish task.

here workaround can use this.

@bindingadapter("touchlistener") public void settouchlistener(view self,boolean value){     self.setontouchlistener(new view.ontouchlistener() {         @override         public boolean ontouch(view view, motionevent event) {             // check if button pressed             if (event.getaction() == motionevent.action_down){                 //do thing             }// check if button released             else if (event.getaction() == motionevent.action_up) {                 //do thing             }             return false;         }     }); } 

and in xml

<button  app:touchlistener="@{true}"}"/> 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -