0

I am using databinding with edittext. The issue i am facing is that, text is lost on orientation change. So i am setting the text on by saving it onSaveInstanceState. But then the focus of the text is shown at the beginning of the text. I verified that edittext has a unique id as that is the main reason where the text is lost.

 <EditText
        android:id="@+id/searchTextView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"


        android:focusable="true"
        android:focusableInTouchMode="true"
        android:imeOptions="actionDone|flagNoExtractUi"
        android:inputType="textNoSuggestions|textEmailAddress"
        android:text="@={searchText}"
        android:textColor="?colorShade1"
        android:textColorHint="?colorShade3"
        android:textSize="28sp" >
        <requestFocus/>
    </EditText>
png
  • 4,368
  • 7
  • 69
  • 118

1 Answers1

0

The issue that you are having may be that the bindings are applied after the view state is restored. In other words, the view state is restored OK with the cursor position set correctly but then that restoration is obliterated by the bindings. The solution is to apply the bindings before view restoration.

How to keep user inputs on screen orientation change with Android DataBinding library? is a post that covers the details of how to do this. And How Do We Get Data Binding To Use Saved Instance State? is a look at a related issue.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131