3

I created a custom compound view, something like

<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:id="@+id/label" />
    <EditText android:id="@+id/edittext" />
</merge>

Of course this is a simplified version.

I've managed to save and restore the view instance state in the java class bound to the view, nonetheless i overrided

@Override
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
    dispatchFreezeSelfOnly(container);
}

@Override
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
    dispatchThawSelfOnly(container);
}

This should prevent save/restore instance state calls to be dispatched to the child views (the TextView and the EditText).

Now i have a fragment containing two of those custom views, with different ids; when an orientation change occurs, the focus always goes to the first EditText after the fragment is recreated. I can't understand why.

For example, let's call edittext1 and edittext2 the edittexts belonging to the custom views with id1 and id2, this is what happens: edittext2 has focus -> orientation change happens -> onSaveInstaceState called on both view -> edittext2 onChangeFocus called (from true to false) -> onRestoreInstanceStateCalled on both view -> edittext1 onFocusChange called (from false to true).

I don't want this to happen, what I'm missing?

ᴛʜᴇᴘᴀᴛᴇʟ
  • 4,466
  • 5
  • 39
  • 73
blian
  • 103
  • 1
  • 6

0 Answers0