我已经创建了 a setOnFocusChangeListener
on anEditText
所以它会抓取字符串并将其添加到TextView
via setText()
。但是,我需要一种公开和动态(以防他们EditText
再次更改)使用该toString()
方法的方法,以便我可以在另一个setOnFocusListener
.
这是我的代码,也许它会以一种不那么令人困惑的方式解释事情:
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:");
}
}
});
(阅读第 5 行的评论)
我有很多焦点听众...我想将它们组合成一个预览,最后为用户生成(使用`setText(textview1 + textview2 + team1Name)