Autofocus in EditText does not work

1

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?

    
asked by anonymous 17.04.2018 / 16:02

1 answer

0

You can put in edittext the field that will receive the next focus, like this:

android:nextFocusDown="@id/seuEdittext"

If your focus is set to the top, do so:

android:nextFocusUP="@id/seuEdittext"
    
20.04.2018 / 16:34