Error in RequestFocus: Only the original thread that created a view hierarchy can touch its views

0

Why do I get an error when I give RequesFocus to my text field?

 public void Set_Conect(String Conect){
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>rrrrrrrrrrrrrrrrrrrrr "+Frg_Logeo.get_usuario ());
            Frg_Logeo.get_conect ().setText ( Conect );
            Usuario.requestFocus ();
        }

In my error it shows me:

  

Only the original thread that created a view of the hierarchy can touch its   views.

That error comes to me through the focus? or is there something wrong that I'm doing?

    
asked by Bloom 30.07.2018 в 20:24
source

1 answer

0

(to specify and help those who have similar problems) use it within my Thread and in the place I want the RequestFocus to come from: (inside your thread - activity main )

runOnUiThread(new Runnable() {
 @Override
 public void run() {
 frg_logeo.Set_Conect ( "Conectar" );
}
});

And you call it from your class that you want to use it:

public void Set_Conect(String Conect){
            Conec.setText ( Conect );
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>rrrrrrrrrrrrrrrrrrrrr ");
            Usuario.requestFocus ( );
    }
    
answered by 31.07.2018 / 15:42
source