只有一个角色自定义的TextView曾进入最后的键盘 [英] Custom TextView with just one character that was entered last from keyboard
问题描述
好吧,我想以某种方式做到以下几点。
在对话框我想用户能够选择一个字母(只能是字母)。他应该能够看到它后,他进入了。如果用户没有使用他的选择感到满意,他应该能够只需点击另一封信。而且他现在应该看到,而不是previous之一时,此信。
Okay, I want somehow do the following. In dialog I want user to be able to choose one letter (only letters). He should be able to see it after he entered it. If user is not satisfied with his choice he should be able simply click at another letter. And he should see this letter now instead of previous one.
我要尽可能多的标准选项尽可能地做到这一点。
我想以某种方式定制的TextView与只显示一个当前输入的字符的能力。或者,也许在某种程度上活动或片段可以拦截只与当前输入的字符,每个输入编辑的TextView从键盘输入,然后。
I want to do it with as much standard options as possible. I think about somehow customise TextView with ability to display only one currently entered character. Or maybe somehow activity or fragment can intercept input from keyboard and then just on every input edit textView with currently entered character.
有人能告诉我如何做?
推荐答案
类成员
private MyTextWatcher mTextWatcher;
private EditText mEditText;
在的onCreate在适当的地方调用setTextWatcher(),例如:
Call setTextWatcher() in appropriate place, for example in onCreate
public void setTextWatcher()
{
mTextWatcher = new MyTextWatcher();
mEditText.addTextChangedListener(mTextWatcher);
}
MyTextWatcher类
MyTextWatcher class
public class MyTextWatcher implements TextWatcher
{
@Override
public void afterTextChanged(Editable s)
{
String text = mEditText.getText().toString();
if (text.length() > 1)
{
mEditText.removeTextChangedListener(mTextWatcher);
mEditText.setText(text.substring(1));
Selection.setSelection(mEditText.getText(), 1);
mEditText.addTextChangedListener(mTextWatcher);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
}
}
这篇关于只有一个角色自定义的TextView曾进入最后的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!