0

I want to change activity only on a particular gesture on a particular view.

For example on Activity A -

  1. double tap on View 1 should change current Activity to B
  2. swipe on View 2 should change current Activity to C
Goofy
  • 6,098
  • 17
  • 90
  • 156
carora3
  • 466
  • 1
  • 5
  • 19

2 Answers2

0

In the OnTouchListener, you can pass the view that triggered the event:

      public boolean onTouch(View v, final MotionEvent event){... this.onClick(v); ...}

just call the functions (IE: onClick) and then check if the view is the one you need to trigger this event:

      public void onClick(View v){
          switch (v.getId()){
              case R.id.X: {DO THIS}
              case R.id.Y: {DO THAT}
Th0rndike
  • 3,406
  • 3
  • 22
  • 42
  • Have u seen an example for this? – carora3 Mar 29 '12 at 13:08
  • I mean can I see that example somewhere online :) – carora3 Mar 29 '12 at 13:13
  • check this out: http://stackoverflow.com/questions/6896173/androidview-and-ontouchlistener – Th0rndike Mar 29 '12 at 13:20
  • I guess my question wasn't so clear. Its like in sequence 1) detect which gesture 2) detect which view 3) see from a table the combination of (Gesture, View , Next Activity) and open that activity. – carora3 Mar 29 '12 at 13:21
  • it doesn't matter. The listeners trigger some functions when a touch event is fired. All you need to do is know how was this event fired (from which view) and act accordingly (if the gesture is a swipe and comes from the view x, do this. if the gesture is a doubleclick and comes from the view Y do that. that way, you create only 1 touch listener and use it from all your views, filtering the activities that should start next. – Th0rndike Mar 29 '12 at 13:24
  • Those are too many questions to answer. There are many touch listener sample codes available in the web, including this same question and answer site. search for one, implement the view filtering like i've shown you, and you'll be on your way to the solution. – Th0rndike Mar 29 '12 at 13:29
  • Thanks for your help. I'm still trying to figure out because I've not worked with gestures before. And right now for e.g. if I swipe too many gestures are called too many times. – carora3 Mar 29 '12 at 13:45
0

Implement the following Listners

1) GestureDetector.OnDoubleTapListener

2) OnGesturePerformedListener

One for Double Tab and Second listner for Swipe, as you will get unimplemented methods call your activity from there.

Bhavin
  • 6,020
  • 4
  • 24
  • 26