Doubt with scenes (Scene)

Asked

Viewed 88 times

4

I’m starting to use scenes in my application, and I’m constantly having the same problem, but now I couldn’t solve.

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

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

And all right, I can pick up the text, because it’s like he just identified 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 take the value of EditText he takes only the value of the first scene.

How can I fix this?

Oncreate from 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>

activity_personalized layout:

<?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;
        }
  • Edit the question and enter the relevant part of the code.

1 answer

2


You must, after the transition, use again 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.