1

I have made an application in android,I made two activites in that and ontouch event i want a swipe effect in that my code is as below but its not working,My code is as below,Please help me for it:

Effect.java

package com.Effects.pageeffects;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.FeatureInfo;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class EffectsActivity extends Activity implements OnTouchListener{
    Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_effects);




    }

      @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            startActivity(new Intent(EffectsActivity.this, Page2Activity.class));

            // Set the transition -> method available from Android 2.0 and beyond
            overridePendingTransition(R.anim.left_to_rigth, R.anim.rigth_to_left);
            return true;

        }

}
jigar
  • 1,423
  • 5
  • 23
  • 46

2 Answers2

1

Write overridePendingTransition(R.anim.left_to_rigth, R.anim.rigth_to_left); in the onCreate() method of Page2Activity after setContentView() method.

Jatin Malwal
  • 4,419
  • 2
  • 21
  • 26
  • i have edited code as per you suggested and code also updated in question,But still not working..! – jigar Aug 08 '13 at 12:31
  • Whats the problem? Whats not working? Can you plz elaborate? Cause I did the same thing and it was working well. – Jatin Malwal Aug 08 '13 at 12:34
  • @jatin-Dear i implement code as you suggested but onswiping on screen next activity should come which is not coming..getting? – jigar Aug 08 '13 at 12:40
  • First try it with a single button click event to check whether its working the way u want. And also place some logs to check r u getting into the onTouch() method? – Jatin Malwal Aug 08 '13 at 12:44
  • Add return false from onTouch() method. – Jatin Malwal Aug 08 '13 at 12:49
  • add log into onTouch method. Check on touch method is invoked or not? – Jatin Malwal Aug 09 '13 at 08:10
  • thing is dat ..that code is working well in OnClick event and same thing i can't do in onTouch event???? – jigar Aug 09 '13 at 11:21
  • I've got why its not working on onTouch. You have to set onTouchListener on the parent view of R.layout.activity_effects layout. like ((RelativeLayout)findViewById(R.id.my_relative_bg)).setOnTouchListener(EffectsActivity.this); – Jatin Malwal Aug 09 '13 at 13:58
-1

You start your activity before override animations.

Kirill Ryabin
  • 183
  • 1
  • 2
  • 14