@联系人光标定位问题解决

来源:互联网 发布:安卓ios数据互通手游 编辑:程序博客网 时间:2024/06/17 00:23

我忽略了代码中的英文注释,特别感谢朋友 戚帅哥 的提醒。
上一篇文章中,说道@了一个联系人以后,回到输入界面,光标会自动跑到文章的最后。这里说一下解决方法:
1、在MentionEditText中,注释掉setText方法

//    @Override//    public void setText(final CharSequence text, BufferType type) {//        super.setText(text, type);//        //hack, put the cursor at the end of text after calling setText() method//        if (mAction == null) {//            mAction = new Runnable() {//                @Override//                public void run() {//                    setSelection(getText().length());//                }//            };//        }//        post(mAction);//    }

2、在activity中,onActivityResult方法中代码稍作修改

if (requestCode == 111 && resultCode == 456456) {            //点击软键盘上的@符号回来的            //和上一篇处理方法一样            mention_et.setText(text);            //新加setSelection这行代码。+1,是因为名字后面加了空格,光标应该定在空格以后            mention_et.setSelection(tempIndex+name.length()+1);        }        if (requestCode == 222 && resultCode == 456456) {            //点击键盘外的@符号            //和上一篇处理方法一样            mention_et.setText(text);            //新加setSelection这行代码。+2,是因为名字后面加了空格,光标应该定在空格以后。并且,之前@符号,也是自己加的。点击键盘上的@符号,Edittext会自动给加上,但是点击外面的,就要自己加了            mention_et.setSelection(tempIndex+name.length()+2);        }
1 0