gettext() returns null when trying to read the typed value in an Edittext

Asked

Viewed 58 times

0

I have an Edittext field and want to save the Text contained in it by pressing a button i tried to do it using the following code but the string remains null

    public void Botao (View view) {
      setContentView(R.layout.content_main_menu);


      EditText valor = (EditText) findViewById(R.id.ValorEdit);
      String ValorF = valor.getText().toString()

Apparently the program is only receiving the previous state of Edittext and not the typed text.

1 answer

3

It’s because you’re setting a new layout. Remove setContentView(R.layout.content_main_menu);

  • worked very thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.