0

I have xml in which I have 2 relative layouts, the first one is map(using map fragments) and the second one is ViewPager layout. I added button to map to hide map when clicked, now I want a method to get back the map layout by sweep down the screen.

I tried setting onTouchListener to relative layout but it is not working, also tried implementing OnTouchListener

public class MainActivity extends FragmentActivity implements OnTouchListener

it is not working! how to achieve this?

  @Override
    public boolean onTouch(View v, MotionEvent event) {

        x= event.getX();
        y=event.getY();

        switch(event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                sX = event.getX();
                sY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                fX = event.getX();
                fY = event.getY();
                if(fX-sX == 0 || fX-sX > 0 || fX-sX <0)
                    if(fY-sY < 0)
                    {

                        if(mapview.getVisibility()==View.GONE)
                        {
                            mapview.setVisibility(View.VISIBLE);

                        }
                    }
                break;
        }
        return true;
    }   
  • also I want to know what exactly the ACTION_DOWN and ACTION_UP mean? –  Aug 30 '13 at 19:17
  • `if(fX-sX == 0 || fX-sX > 0 || fX-sX <0)` Umm, what? Why not just use `if(true)` or leave it out altogether? – Geobits Aug 30 '13 at 19:41
  • 1
    On topic, though, your `ViewPager` is probably intercepting the touch event. Can you log this method to see if it's even called? – Geobits Aug 30 '13 at 19:42
  • I'm even unable to determine whether this method is being called or not. –  Aug 30 '13 at 19:47
  • add a line to it that says `Log.d("TouchTest", "called!");`, and look for that in logcat while running. Side note: You may want to read up on logging/debugging techniques. – Geobits Aug 30 '13 at 19:50
  • nope! I don't see the message! Side note: @Geobits thanks for the suggestion. –  Aug 30 '13 at 19:56
  • 1
    Then it's being intercepted. You can google around to override that, or this may help: http://stackoverflow.com/a/8122680/752320 – Geobits Aug 30 '13 at 19:57
  • thanks a lot! @Geobits, between I have a ListView in the ViewPager, so I cannot do that! –  Aug 30 '13 at 20:02
  • I wouldn't recommend using a `ListView`, `ViewPager`, *and* scrolling gestures all on the same screen. It will just confuse the system, and is generally not recommended. It might be easier to figure out another design for this interaction. – Geobits Aug 30 '13 at 20:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36570/discussion-between-vkn-and-geobits) –  Aug 30 '13 at 20:13

1 Answers1

0

Post your code, btw in simple way, ACTION_DOWN is when you touch the screen, ACTION_UP is when you finger release the screen. Look here

Igor Morais
  • 645
  • 1
  • 8
  • 13
  • To be more exact, `ACTION_DOWN` is when the *first* finger touches the screen, and `ACTION_UP` is when the *last* finger lifts. For anything in between, you need to use the `ACTION_POINTER_xxx` options instead. – Geobits Aug 30 '13 at 19:39