android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.05k stars 3.01k forks source link

ConstraintLayout: EditText in Group #51

Open Saba-21 opened 5 years ago

Saba-21 commented 5 years ago

When EditText is in a group, EditText.requestFocus() is not working after group's visibility change.

Saba-21 commented 5 years ago

this is not working: focus is still on firstField, (focus is on secondField only on second click)

someLayout.setOnClickListener {
    grSomething.visibility = Group.VISIBLE
    secondField.requestFocus()
}
<EditText
        android:id="@+id/firstField"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#0f0"
        app:layout_constraintWidth_percent=".5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/secondField"/>

<EditText
        android:id="@+id/secondField"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#00f"
        app:layout_constraintWidth_percent=".5"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/firstField"/>

<android.support.constraint.Group
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/grSomething"
        android:visibility="gone"
        app:constraint_referenced_ids="secondField"/>
davidfon commented 5 years ago

I can confirm this issue as well. If you call secondField.visibility = View.Visible, the secondField.requestFocus() works as expected, but when the visibility of secondField is set through grSomething.visibility = Group.VISIBLE then secondField never receives focus.