0

I can't override the onSwipe() method. The error is "The method onSwipe(int) of type Adds must override or implement a supertype method". Can anyone tell me what I did wrong?. I want to navigate between activities using swipe gesture. Is there any other way to do it? If so please explain. Do I have to import any more packages?

package com.mahavega.qcdemo;

import com.mahavega.qcdemo.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class Adds extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ads);
        TextView tv1 = (TextView) findViewById(R.id.textView1);
        tv1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(Adds.this, Ads2.class));
            }
        });
        ImageView im1 = (ImageView) findViewById(R.id.imageView1);
        im1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(Adds.this, Real.class));
            }
        });
    }
    @Override
    public void onSwipe(int direction) {
        Intent intent = new Intent();

        switch (direction) {
        case SimpleGestureFilter.SWIPE_RIGHT:
            intent.setClass(this, Ads2.class);
            break;

        case SimpleGestureFilter.SWIPE_LEFT:
            intent.setClass(this, Ads3.class);
            break;
        }

        startActivity(intent);
    }
}
Mateusz Kowalczyk
  • 2,036
  • 1
  • 15
  • 29
Sumodh S
  • 709
  • 1
  • 14
  • 36

2 Answers2

3

your activity should implement SimpleGestureListener to be able to recieve gesture events.

public class Adds extends Activity implements OnGestureListener
sokie
  • 1,966
  • 22
  • 37
  • shows error "SimpleGestureListener cannot be resolved to a type" – Sumodh S Mar 25 '13 at 14:35
  • my bad,it was a typo,it should be SimpleOnGestureListener – sokie Mar 25 '13 at 14:39
  • take a look here: http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html – sokie Mar 25 '13 at 14:41
  • corrected answer,the interface that you should implement is OnGestureListener,please try it and let me know – sokie Mar 25 '13 at 15:28
  • Also it could be easier to implement your own gesture listener that extends SimpleOnGestureListener if you want to listen only to a certain subset.You should definitely take a look on android developer for more info – sokie Mar 25 '13 at 15:29
  • please review my code I posted below and tell me what I have to do next – Sumodh S Mar 25 '13 at 16:14
0

Your error reads from the fact that Activity does not have an onSwipe(int) method. So the error is stating that you cannot override a method that has no super method. Also as @sokie said, check out the OnGestureListener from the link he added.As for swiping gesture used to start new activities, when swiping left to right, override call onBackPressed (like you are going back) and on swipe right to left start new activity. Although this means you have to create the gesture listener in each of your activities.

Raigex
  • 1,205
  • 12
  • 32
  • how to get those swipe events?? – Sumodh S Mar 25 '13 at 14:58
  • you get swipe events by implementing that listener.If you have problems you should let your IDE help you when importing packages – sokie Mar 25 '13 at 15:21
  • @o3n you implement an onTouchListener to your application, then you pass the events to a gesture listener, you should have an idea after reading this post > http://stackoverflow.com/a/938657/1359802 – Raigex Mar 25 '13 at 15:28
  • @Raigex that is really old code,android now support proper gesture detection,and implementing the interface linked is a better aproach,as it does pretty much what is showed in that thread. – sokie Mar 25 '13 at 15:32
  • Did not know that, I was using that the last time I thought I needed gesture detection. Good to know though. – Raigex Mar 25 '13 at 15:33
  • @sokie You said that its old code.. But how to do it in proper way? please give an example code – Sumodh S Mar 25 '13 at 16:38