I’ve created a setOnFocusChangeListener on an EditText so it will grab the string and add it to a TextView via setText(). However, I need a way to publicly and dynamically (in case they change the EditText again) use the toString() method so I can use it in another setOnFocusListener.
Heres my code, perhaps it will explain things in a less confusing way:
final TextView team1NameScore = (TextView) findViewById(R.id.team1NameScore);
final EditText team1Name = (EditText) findViewById(R.id.team1Name);
team1Name.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
String team1NameString = team1Name.getText().toString();
// Right here I need to make the above line public so I can use it later!
if (!hasFocus) {
team1NameScore.setText(team1NameString + "'s Score:");
}
}
});
(Read the comment on the 5th line)
I have many focus listeners… I’d like to combine them into one preview that I generate for the user at the end (using `setText(textview1 + textview2 + team1Name)
Simply create a field variable:
Then use it like any other variable: