Reputation: 53657
I have set OnTouchListener to an image view. I want to do two different actions when user press down the image and also when press up the image. But always I am getting press down event as (ACTION_DOWN) but if i use button instead of ImageView then I can both ACTION_DOWN and ACTION_UP. But I have to use ImageView not Button. How to achieve ACTION_UP event in ImageView
prevImage.setOnTouchListener(this); // prevImage is an image View
@Override
public boolean onTouch(View view, MotionEvent arg1) {
// TODO Auto-generated method stub
Log.i("Wallpaper","...On touch ..." + arg1.getAction());
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
//set img1 as imagesource
} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
//set img2 as imagesource and parse data from url
}
return false;
}
Thanks
Upvotes: 3
Views: 2050
Reputation: 71
Don't know if this is too late or not.
You can do it by adding this to your imageView in your xml file
android:clickable="true"
and you can use if and else if like you already did there.
hope this helps.
Upvotes: 7
Reputation: 13600
Please check if ACTION_CANCEL
is fired instead of ACTION_UP. It may get fired instead of ACTION_UP when it comes to images.
[EDIT] Also, you have to return true
if you intercept ACTION_DOWN event in order ACTION_UP to get fired.
Upvotes: 1