Home > Mobile >  Android the same button can set a touch to monitor and a click to monitor events??
Android the same button can set a touch to monitor and a click to monitor events??

Time:10-05

The same button can set a touch to monitor and a click to monitor events? If you can how should I deal with the relationship between the two?

CodePudding user response:

Can look at the controls of OnTouchListener
The button.. SetOnTouchListener (new the OnTouchListener () {
@ Override
Public Boolean the onTouch (View v, MotionEvent event) {
return false;
}
});
As well as the type MotionEvent events

CodePudding user response:

Can ah, I was doing so, to touch to change font color, click click execution time, touch not click, because when finger according to move to the outside of the button to lift will not implement the click event,

 nextButton. SetOnTouchListener (new the OnTouchListener () {
@ Override
Public Boolean the onTouch (View v, MotionEvent event) {
If (nextButton isEnabled ()) {
If (event. GetAction ()==MotionEvent. ACTION_DOWN) {
Xff000000 nextButton. SetTextColor (0);
} else if (event. GetAction ()==MotionEvent. ACTION_UP | | event. The getAction ()==MotionEvent. ACTION_CANCEL) {
NextButton. SetTextColor (0 XFFFFFFFF);
}
}
return false;
}
});
NextButton. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

}
});

CodePudding user response:

refer to the second floor ink_s response:
can ah, that's how I do, touch to change font color, click click execution time, touch not click, because when finger according to move to the outside of the button to lift will not implement the click event,

 nextButton. SetOnTouchListener (new the OnTouchListener () {
@ Override
Public Boolean the onTouch (View v, MotionEvent event) {
If (nextButton isEnabled ()) {
If (event. GetAction ()==MotionEvent. ACTION_DOWN) {
Xff000000 nextButton. SetTextColor (0);
} else if (event. GetAction ()==MotionEvent. ACTION_UP | | event. The getAction ()==MotionEvent. ACTION_CANCEL) {
NextButton. SetTextColor (0 XFFFFFFFF);
}
}
return false;
}
});
NextButton. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

}
});

That if there are several need to click the button and imagebutton?

CodePudding user response:

refer to the second floor ink_s response:
can ah, that's how I do, touch to change font color, click click execution time, touch not click, because when finger according to move to the outside of the button to lift will not implement the click event,

 nextButton. SetOnTouchListener (new the OnTouchListener () {
@ Override
Public Boolean the onTouch (View v, MotionEvent event) {
If (nextButton isEnabled ()) {
If (event. GetAction ()==MotionEvent. ACTION_DOWN) {
Xff000000 nextButton. SetTextColor (0);
} else if (event. GetAction ()==MotionEvent. ACTION_UP | | event. The getAction ()==MotionEvent. ACTION_CANCEL) {
NextButton. SetTextColor (0 XFFFFFFFF);
}
}
return false;
}
});
NextButton. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

}
});

That if there are several need to click the button and imagebutton?

CodePudding user response:

Will click it will have to do is set an OnClickListener!

CodePudding user response:

Do touch events interceptor operations, to judge the different touch and have to do is click event, is to distribute in the inside of the incident response process, can be set inside interception, and respond to events
  • Related