Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Animations and Transitions The Transitions Framework Transitioning Back and Forth

Finally, fix onButtonClicked () method so that the mTransition successfully transitions to the new current scene when th

i have added the mTransitionManager = new Transition in the onButtonClicked(Veiw)

MainActivity.java
public class MainActivity extends Activity {

    protected TransitionManager mTransitionManager;
    protected Scene mScene1;
    protected Scene mScene2;
    protected Scene mCurrentScene;
    protected TransitionSet mForwardSet;
    protected TransitionSet mBackwardSet;

    // Some code omitted for brevity

    public void onButtonClicked(View view) {
      mTransitionManager = new TransitionManager();

        if (mCurrentScene == mScene2) {
            mCurrentScene = mScene1;
        }
        else {
            mCurrentScene = mScene2;

          mTransitionManager.transitionTo(mCurrentScene);
        }

    }

    protected void setupTransitions() {
        // These methods are setting up scenes and transitions sets like in the video
        initScenes();
        initSets(); 

        // Start here!
     mTransitionManager = new TransitionManager();
      mTransitionManager.setTransition(mScene1, mScene2, mForwardSet);
      mTransitionManager.setTransition(mScene2, mScene1, mBackwardSet);
      mScene1.enter();


    }

}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Melody Mudehwe ! I received your request for assistance, and from my perspective, it looks like you're doing terrific! The problem here is placement.

This is the line that makes the scene transition when the button is clicked:

 mTransitionManager.transitionTo(mCurrentScene);

But you've placed it inside your else statement which means it will only ever run if the current scene is scene1. Moving it outside your else statement causes this to pass. It will always run regardless of what the scene is when it is clicked.

Hope this helps! :sparkles:

Thank you for your help. I have placed the mTransitionManager.transitionTo(mCurrentScene) outside the else statement. but it's still not working it is now showing an error on the mTransitionManager = newTransitionManager(); in the onButtonClicked(View, view). look at the above code if its correct where i insert it.

Its question 4/4

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Melody Mudehwe my passing code is almost identical to yours besides the placement of that one line. I would need to see your whole code as it appears now to have an idea what the problem is. It could be that you accidentally deleted a curly brace or a parenthesis or something. Here was my passing code for step 4/4 for that function:

 public void onButtonClicked(View view) {
      mTransitionManager = new TransitionManager();

        if (mCurrentScene == mScene2) {
            mCurrentScene = mScene1;
        }
        else {
            mCurrentScene = mScene2;
        }
    mTransitionManager.transitionTo(mCurrentScene);
    }

If this still doesn't work, it could potentially be a caching issue. You might try restarting the challenge from the beginning and copying the code in from step 1.

Hope this helps! :sparkles:

Thank you Jennifer. Problems solved now, found the error.