Home Android OnTouch Listener Doesn't work when App is on Release mode
Reply: 0

Android OnTouch Listener Doesn't work when App is on Release mode

user2526
1#
user2526 Published in May 27, 2018, 3:38 am

In one of my Activities, I have an ImageView which I set to it onTouchListener, in order to move it on the screen, the problem is that when I test it on debug mode everything works fine and I see that the ImageView is moving on the screen and I also can click on that. But, when I create a signed APK for release mode and test it on the same device, it doesn't respond!

the image view is inside a RelativeLayout and configured as:

 <ImageView
    android:id="@+id/imageView"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:layout_centerInParent="true"
    android:src="@drawable/app_launcher"
    android:clickable="true"
 />

and the code for that is: (this code is found in onCreate method)

imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event))
            {
                Toast.makeTest(MainActivity.this, 
                                  "imageView clicked!",Toast.LENGTH_LONG).show();
                return true;
            } else {
                switch (event.getActionMasked()) {
                    case MotionEvent.ACTION_DOWN:
                        initPosX= v.getX();
                        initPosY= v.getY();

                        initTouchX= event.getRawX();
                        initTouchY= event.getRawY();

                        lastAction= event.getAction();

                        return true;

                    case MotionEvent.ACTION_MOVE:
                        v.setX(initPosX+ (int)(event.getRawX() - initTouchX));
                        v.setY(initPosY+ (int)(event.getRawY() - initTouchY));

                        lastAction= event.getAction();
                        return true;

                    case MotionEvent.ACTION_UP:
                        v.setVisibility(View.VISIBLE);
                        lastAction= event.getAction();
                        return true;
                }
            }
            return true;

        }
    });

I have also a GestureDetectorListener to detect singleTap:

private class GestureListener extends GestureDetector.SimpleOnGestureListener{
    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        return true;
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311663 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO