我试图在 stackoverflow 中的其他线程上找到答案,但实际上找不到。我正在实现一个TextWatcher
,当我开始输入文本时,它会移动到初始位置并继续在右侧添加文本。所以我添加 edittext.setSelection(scene.getText().length());
了将光标移动到最右边,但是现在当我点击任何地方的文本时,光标移动到初始位置并且不再工作了。我希望我的光标在我键入时沿着文本移动,我应该怎么做。这是我的TextWatcher
scene.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//here is your code
strcheck = s.toString().substring((s.length() - 1), s.length());
if (nowUpper)
strcheck = strcheck.toUpperCase();
else if (nowLower)
strcheck = strcheck.toLowerCase();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
if (nowUpper) {
if (ix == 1) {
ix = 0;
scene.setText(scene.getText().toString().substring(0,scene.length() - 1) + strcheck);
// scene.setSelection(scene.getText().length());
} else {
ix = 1;
}
// TODO Auto-generated method stub
}
}
});