I am at the very beginning of a new Android project. After playing with MVP in my last project, I want to implement MVVM with data binding this time.
I have a problem handling the DataBinding correctly when it comes to configuration changes, such as changing the orientation of the screen.
All DataBinding samples (everything that I found when searching for βandroid mvvm data bindingβ) have the same problem: When I enter something into EditText and rotate the screen, then EditText is empty.
Once in my layout there is something like the following: I canβt get the views (EditText in this case) to restore their state after changing the rotation of the screen.
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="vm"
type="com.example.app.TestViewModel" />
</data>
<EditText android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@={vm.question}"
android:hint="Question" />
</layout>
, - onCreate .
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityTestBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_test);
binding.setVm(new TestViewModel());
}
?
, .