Search code examples
androidanimationoverriding

The method overridePendingTransition(int, int) is undefined for the type new View.OnClickListener(){}


I tried to add animation on start activity intent and I got this error. It's the first time I've seen something like this, I looked up on google and SO but I was unable to find anything that would help me solve this issue. So how can I fix this? Whats wrong with my code?

holder.transfer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            @SuppressWarnings("unused")
            int clickedposition = (Integer) v.getTag();
            Intent iv = new Intent(context,
                    MenuActivity.class);

            if (iv != null) {
                iv.putExtra("NAME", ringNames[position]);
                int [] res = songPos;
                iv.putExtra("PATH", res[position]);
                iv.putExtra("FILE", ringNames[position]+".mp3");
                ((Activity) context).startActivity(iv);
                overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);
            }

                 try
                  {
                    CentralActivity.playing = Boolean.valueOf(false);
                    CentralActivity.mp.stop();
                    CentralActivity.mp.release();

                    return;
                  }
                  catch (Exception localException)
                  {

                  }

        }
    });

I get error The method overridePendingTransition(int, int) is undefined for the type new View.OnClickListener(){} thanks


Solution

  • Replace your:

    overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);
    

    with:

     ((Activity) context).overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);
    

    You need to call the method overridePendingTransition from an activity, but you do it in a OnClickListener.