0

I'm new to transition and trying a basic example. There are two buttons, "DOWN" and "UP", in the layout. If you click "DOWN", both buttons are supposed to move down to the bottom of screen. If you click "UP", both buttons are supposed to move up to the top of screen.

"DOWN" button works as expected, but when I click "UP" button, nothing happens other than ripple effect on the button. I inserted Log statement in "UP" button's onClick(), but it is not called.

Please point out what I am doing wrong.

Here is the repo. https://github.com/gs20060101/TransitionExperiments.git

Below are some relevant files.

MainActivityFragment.java

public class MainActivityFragment extends Fragment {

    private Scene mScene1;
    private Scene mScene2;

    public MainActivityFragment() {
    }

    @Override
    public View onCreateView(
        LayoutInflater inflater,
        ViewGroup container,
        Bundle savedInstanceState
    ) {

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        ViewGroup sceneRoot = (ViewGroup) rootView.findViewById(R.id.scene_root);

        mScene1 = new Scene(sceneRoot, (ViewGroup) sceneRoot.findViewById(R.id.scene));

        mScene2 = Scene.getSceneForLayout(
            sceneRoot,
            R.layout.fragment_transition_scene_2,
            getActivity()
        );

        Button downButton = (Button) rootView.findViewById(R.id.downButton);
        downButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.go(mScene2);
            }
        });

        Button upButton = (Button) rootView.findViewById(R.id.upButton);
        upButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.go(mScene1);
            }
        });

        return rootView;
    }
}

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@+id/scene_root"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.gens.transitionplay.MainActivityFragment">

    <include layout="@layout/fragment_transition_scene_1"/>

</FrameLayout>

fragment_transition_scene_1.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:id="@+id/scene"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

    <Button
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView"
        android:text="Go"/>

    <Button
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/downButton"
        android:layout_toRightOf="@id/downButton"
        android:text="Back"/>

</RelativeLayout>

fragment_transition_scene_2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

    android:id="@+id/scene"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

    <Button
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Down"/>


    <Button
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/downButton"
        android:layout_toRightOf="@id/downButton"
        android:text="Up"/>

</RelativeLayout>
Libelle
  • 806
  • 7
  • 14
  • Take a look at: http://stackoverflow.com/a/28921633/6526330. This seems to be an issue with having different views with the same id's in two different scenes. The result is that the buttons in the first scene get the listeners and not the buttons in the second scene. – Dr. Nitpick Jul 23 '16 at 05:45
  • I agree, it's essentially the same problem. Thanks. – Libelle Jul 23 '16 at 06:00

0 Answers0