EditText.requestFocus()
工作不正常时,它在一个组被添加,
我删除了网上论坛,并且工作正常。
这不起作用:焦点仍然放在firstField
上(焦点仅在第二次点击时焦点在secondField
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"/>
这是有效的:重点放在secondField
someLayout.setOnClickListener {
secondField.visibility = View.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"
android:visibility="gone"
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"/>