Android Setonlongclicklistner Does Not Work With Ontouch Event
Solution 1:
I think that the Object can have either an onClick or an onTouch, and it will use whatever the last one defined is. I have noticed this recently in some of my apps too.
Solution 2:
According to the developer docs
returning true from these event listeners will stop the propagation of the event to other event listeners and will also block the callback to the default event handler in the View.So be certain that you want to terminate the event when you return true
So perhaps returning false in your methods that handle the events would bring you a step closer to what you want to achieve
Solution 3:
I tried the "returning false". It will trig both of them. For the following example, it will show the different message on the Title.
publicbooleanonTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub int ea=event.getAction();
switch(ea){
case MotionEvent.ACTION_MOVE:
int l=v.getLeft();
int b=v.getBottom();
int r=v.getRight();
int t=v.getTop();
Stringmessage="l:"+l + "t:" + t+
"r:"+r + "b:"+ b;
this.setTitle(message);
}
returnfalse;
}
@OverridepublicvoidonClick(View v) {
// TODO Auto-generated method stubthis.setTitle("Click");
}
@OverridepublicbooleanonLongClick(View arg0) {
// TODO Auto-generated method stubthis.setTitle("Long Click");
returnfalse;
}
Solution 4:
it's working fine with me after Searching and Try and Error and Hope to work with you Well
1-add android:clickable="true" to ImageView in XML
2-in your Activity or View and make sure to return false ;
imageView.setOnTouchListener(newOnTouchListener() {
@TargetApi(11)publicbooleanonTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.v(TAG, "Touched Here");
returnfalse;
}
});
3- then and last step make sure to return true;
imageView.setOnLongClickListener(newOnLongClickListener() {
publicbooleanonLongClick(View v) {
// TODO Auto-generated method stubLog.v(TAG, "Long Pressed Here");
returntrue;
}
});
it's will work well to Touch and Long Press
Post a Comment for "Android Setonlongclicklistner Does Not Work With Ontouch Event"