使用textwatcher或者有一种方法我可以在我的edittext中输入一个单词说蓝色 让每个字符分割并在多个文本视图上设置文本
textview1显示b textview2显示l textview3显示你 textview4显示e
感谢所有给予的帮助。答案 0 :(得分:2)
String str = edittext.gettext().toString();
char[] charArray = str.toCharArray();
Character[] charObjectArray = ArrayUtils.toObject(charArray);
textview1.settext(charObjectArray[0].toString());
textview2.settext(charObjectArray[1].toString());
textview3.settext(charObjectArray[2].toString());
textview4.settext(charObjectArray[3].toString());
答案 1 :(得分:0)
尝试在Android
中正常使用此代码
String s=t.getText().toString();
char charArray[] = s.toCharArray();
for(int i=0;i<charArray.length;i++){
char r=charArray[i];
Toast.makeText(getApplicationContext(), ""+r, Toast.LENGTH_LONG).show();
}
答案 2 :(得分:0)
如果你真的想使用textwatcher那么你可以使用我的方法@Digvesh方法是正确的。首先在您的editText中添加一个TextWatcher。
editText.addTextChangedListener(mTextEditorWatcher);
// EditTextWacther Implementation
private final TextWatcher mTextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
// When No text is Entered
}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
// during typing
}
public void afterTextChanged(Editable s)
{
String str = edittext.gettext().toString();
if(str.length() ==3){
char [] characterArray = new char[str.length()];
textview1.settext(characterArray [0].toString());
textview2.settext(characterArray [1].toString());
textview3.settext(characterArray [2].toString());
textview4.settext(characterArray [3].toString());
}
}
};