Andrew Quebe
Andrew Quebe

Reputation: 2293

Using Android Window Animations in a Fragment

I have a fragment that I'm working with which has scrollable tabs in it. I have a button on one of the fragments which opens a sub activity. I want to use the translate animation that Android offers but it's giving me errors.

Button onClickListener code:

button.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        Intent intent = new Intent(getActivity(), SubActivity.class);

        Bundle translateBundle = ActivityOptions.makeCustomAnimation(getActivity(),
        R.anim.slide_in_left, R.anim.slide_out_left).toBundle();

        startActivity(intent, translateBundle);
    }
});

Android Studio is giving me this error:

startActivity (Intent) in Fragment cannot be applied to (Intent, android.os.Bundle)

I tried searching S.O. for something like this but didn't find anything.

Help is much appreciated!

Upvotes: 0

Views: 1305

Answers (2)

adneal
adneal

Reputation: 30794

You're receiving that error because you're using the support library Fragment which doesn't have a wrapper for Context.startActivity(Intent intent, Bundle options).

Instead you could pass your Bundle using getActivity.startActivity(Intent, Bundle):

getActivity().startActivity(intent, translateBundle);

Alternatively, you could use ActivityCompat.startActivity(Activity, Intent, Bundle.

Upvotes: 1

sandy
sandy

Reputation: 213

Edited Answer Try this!!

  Intent intent = new Intent(getActivity(), SubActivity.class);

    startActivity(intent)

   getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left)

Upvotes: 1

Related Questions