当我们想要正确猜出Textwatcher
的单词时,如何使用EditText
更改EditText
数组的背景颜色?
示例:
public EditText[] edts=new EditText[9];
String[] etd={"f","m","v","f","m","v","f","m","v"};
答案 0 :(得分:0)
只需在所有EditTexts中添加onTextChangedListener
:
public EditText[] edts=new EditText[9];
String[] etd={"f","m","v","f","m","v","f","m","v"};
private void addTextChangedListeners() {
for (int i = 0; i < edts.length; i++) {
final int idx = i; //necessary for inner class
edts[i].addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//No implementation needed.
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().equals(etd[idx])) {
edts[idx].setBackgroundColor(Color.parseColor("#FF00FF"));
}
}
@Override
public void afterTextChanged(Editable s) {
//No implementation needed.
}
});
}
}