Doubt with scenes (Scene)

4

I'm starting to use scenes in my application, and I'm constantly having the same problem, but now I did not know how to solve.

So, I have 2 scenes, and in onCreate I get my views, for example:

editText = (EditText) findViewById(R.id.edit_text);

And okay, I can get the text, because it's as if it identifies only the EditText of the first scene. But when I'm in the second scene, I have the same item with the same Id , but when I try to get the value of EditText it only takes the value of the first scene.

How can I resolve this?

OnCreate of activity:

RelativeLayout baseLayout = (RelativeLayout) findViewById(R.id.activity);

        View startViews = getLayoutInflater()
                .inflate(R.layout.activity_normal, baseLayout, false);

        View endViews = getLayoutInflater()
                .inflate(R.layout.activity_personalized, baseLayout, false);

        scene1 = new Scene(baseLayout, startViews);
        scene2 = new Scene(baseLayout, endViews);

        anticipateTransition = new ChangeBounds();
        anticipateTransition.setDuration(700);
        anticipateTransition.setInterpolator(new AnticipateInterpolator());

        transition = new ChangeBounds();
        transition.setDuration(500);
        transition.setInterpolator(new DecelerateInterpolator());

        scene1.enter();
        start=true;

layout.activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">

</RelativeLayout>

layout.activity_normal:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">
     <EditText android:id="@+id/edit_text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
</RelativeLayout>

layout.activity_personalized:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">
     <EditText android:id="@+id/edit_text"
          android:layout_alignParentBottom="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
</RelativeLayout>

Method for transition

        if (start) {
            TransitionManager.go(scene2, anticipateTransition);
            start = false;
        } else {
            TransitionManager.go(scene1, transition);
            start = true;
        }
    
asked by anonymous 01.10.2016 / 19:15

1 answer

2

You must, after the transition, reuse findViewById(R.id.edit_text);

if (start) {
    TransitionManager.go(scene2, anticipateTransition);
    editText = (EditText) findViewById(R.id.edit_text);
    start = false;
} else {
    TransitionManager.go(scene1, transition);
    editText = (EditText) findViewById(R.id.edit_text);
    start = true;
}
    
02.10.2016 / 19:55