1
I have a EditText that always needs to be in focus, and a Button whichever:
<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 execute the method, it does not respect the 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();
}
}
Setando no onCreate:
this.limpar.setFocusable(false);
That way it works. But if I have several elements (Button, Layout, etc), I need to keep setFocusable(false), and sometimes even setando everything, does not work.
It would have been possible to use only the requestfocus() in the EditText, without having to set other things ?