【问题标题】:Not able to move cursor along the text on editText无法沿editText上的文本移动光标
【发布时间】:2016-07-20 14:56:54
【问题描述】:

我试图在 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
        }
    }
});

【问题讨论】:

    标签: android android-edittext


    【解决方案1】:

    这是因为您添加了 2 个编辑文本 - Probani

    【讨论】:

      猜你喜欢
      • 2016-06-14
      • 2011-12-17
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多