1
我試圖實現TextWatcher根據每個文本中的文本更改相對佈局中的每個EditText的文本顏色。我也有一個按鈕,當我點擊按鈕時,監聽器首次使用TextWatcher隨機填充EditText(「IRE」,「SCO」...等)。Android TextWatcher根據文本更改EditText文本顏色。多個EditText
代碼:
public class MainActivity extends Activity implements TextWatcher{
private EditText team1,team2,team3,team4,team5,team6,team7,team8, team9,team10,team11,team12,team13,team14,team15;
private EditText text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.luckdipbutton);
holeScores = new ArrayList<EditText>();
rl = (ScrollView) findViewById(R.id.scrollView);
rl.setBackgroundColor(Color.BLACK);
team1 = (EditText) findViewById(R.id.team1);
// team1.addTextChangedListener(this);
team2 = (EditText) findViewById(R.id.team2);
team3 = (EditText) findViewById(R.id.team3);
team4 = (EditText) findViewById(R.id.team4);
team5 = (EditText) findViewById(R.id.team5);
team6 = (EditText) findViewById(R.id.team6);
team7 = (EditText) findViewById(R.id.team7);
team8 = (EditText) findViewById(R.id.team8);
team9 = (EditText) findViewById(R.id.team9);
team10 = (EditText) findViewById(R.id.team10);
team11 = (EditText) findViewById(R.id.team11);
team12 = (EditText) findViewById(R.id.team12);
team13 = (EditText) findViewById(R.id.team13);
team14 = (EditText) findViewById(R.id.team14);
team15 = (EditText) findViewById(R.id.teamwinner);
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.toString().equals("IRE"))
{
this.text.setTextColor(Color.GREEN);
}
else if (s.toString().equals("SCO"))
{
this.text.setTextColor(Color.WHITE);
}
else if (s.toString().equals("AUS"))
{
this.text.setTextColor(Color.YELLOW);
}
else if (s.toString().equals("NZL"))
{
this.text.setTextColor(Color.RED);
}
else {
}
}
我不明白。你的問題是什麼? – nbaroz
「team1」的textwatcher也是如此? – JAPK
嘗試將TextWatcher添加到每個視圖。 –