I've created an app where your layout contains an EditText and a TextView .
The initial content of the TextView is: "unnamed" .
I'dliketheTextViewcontenttobechangedwhenIputsomethinginEditText,whichdoesnothappen:
I'veusedastringtocaptureEditTextcontentfortheTextViewdisplaythecontentsofit,sinceI'llalsoneedtoexporttoanextactivity.SoIdonotusesomethingdirectlike:
TextView.setText(editText)
,butTextView.setText(String)
.
MainActivity.java:
packagegenesysgeneration.ettotv;importandroid.support.v7.app.AppCompatActivity;importandroid.os.Bundle;importandroid.widget.EditText;importandroid.widget.TextView;publicclassMainActivityextendsAppCompatActivity{privateEditTextetNome;privateTextViewtvNome;privateStringnome;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){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);
}
}
}