我想检查String(来自EditText)是否是String Array的一部分,我需要索引。我已将TextWatcher添加为TextChangedListener,如下所示:
在Activity-Class中:
private String[] randomSpanishWords = { "pueblo", "madre" };
private TextWatcher ETListener = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
int index = Arrays.asList(randomSpanishWords).indexOf(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
}
};
onCreate()中的:
editText1.addTextChangedListener(ETListener);
无论我在EditText中输入什么内容,索引始终为-1。我错过了什么?
答案 0 :(得分:1)
尝试使用
将charSequence转换为StringcharSequence.toString()
或者为阵列使用CharSequence
private CharSequence[] randomSpanishWords = { "pueblo", "madre" };