0
I created an app where in its layout contains a Edittext and a Textview.
The initial content of Textview is: "nameless".
I would like the content of Textview was changed when I inserted something into Edittext, what does not occur:
I used a string to capture the content of Edittext to the Textview display its contents, as I will also need to export to a next Activity. So it doesn’t serve me something direct like:
TextView.setText(editText)
, but yes TextView.setText(String)
.
Mainactivity.java:
package genesysgeneration.ettotv;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText etNome;
private TextView tvNome;
private String nome;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNome=(EditText)findViewById(R.id.etNome);
tvNome=(TextView)findViewById(R.id.tvNome);
if (etNome.getText().length()==0){
nome="SEM NOME";
tvNome.setText(nome);
}else {
nome=etNome.getText().toString();
tvNome.setText(nome);
}
}
}
Funfou, is now showing the delay of a character in Textview. Type... type the name "Horse" in Edittext, in Textview appears "Caval". Deleting a character or adding there yes appears "Horse", but the contents of Edittext and Textview are never equal.
– Boneco Sinforoso
I put on onTextChanged and everything was quiet!!!
– Boneco Sinforoso
String value is not changing!!!
– Boneco Sinforoso
@Dummy symphore you saw the explanation about onTextChanged right?! Beauty, if it works for you right, just validate the answer. Good luck!
– viana
string value is not changing!!!
– Boneco Sinforoso
@Puppet Symphore put the
nome = s.toString();
also within theonTextChanged
that will change.– viana
@Dummy symphore in this way, its string also receives the value that is inside the
EditText
– viana