I have a EditText
that always needs to be in focus, and a Button
any:
<EditText
android:id="@+id/edtCod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<Button
android:id="@+id/btnLimpar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="limpar"
android:text="Limpar" />
When I run the method, it does not respect requestfocus()
and "jump" to the button.
Method:
public void confere(View view) {
String codigo = cod.getText().toString();
try {
salvar(codigo);
cod.setText("");
cod.requestFocus();
} catch (IOException e) {
e.printStackTrace();
}
}
Setting no onCreate
:
this.limpar.setFocusable(false);
That way it works. But if I have multiple elements ( Button
, Layout
, etc), I need to set setFocusable(false)
, and sometimes even setting everything does not work.
Would you like to use only requestfocus()
in EditText
, without having to set other things?