I have a problem with touch listener in my android application. OnTouchLIstenr is not working for the view, i.e ACTION_DOWN is performing well in the listener but ACTION_UP doesnt invokes. i dont know whats the problem going on. But if i set the dummy click listener, both working fine. Why is it so?
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView image = (ImageView) findViewById(R.id.image);
    image.setOnTouchListener(new OnTouchListener() {            
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView img = (ImageView) v;
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN){
                img.setImageResource(R.drawable.port);
            }else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){
                img.setImageResource(R.drawable.bar);
            }               
            return false;
        }
    });
}
                You might consider, returning 'true', since you are handling the touch event.
Link to a similar question. Answer from adamp, makes sense
image.setOnTouchListener(new OnTouchListener() {            
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView img = (ImageView) v;
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN){
                img.setImageResource(R.drawable.port);
            }else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){
                img.setImageResource(R.drawable.bar);
            }               
       return true;
        }
    });
just replace return true; instead of return false; and check
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With