求教关于listview内edittext点击修改内容的问题

我现在在做一个listview,
想要实现的效果是:点击每个item一下,可以默认选中不带后缀名的内容,如点击内容为“pic.jpg”会选中“pic”,并且键盘弹出可进行内容修改

我在listview的item里放的是edittext,并在adapter里对edittext进行了setOnFocusChangeListener的监听,为的是能点击后直接选中不带后缀名的字符串内容

但问题是,运行后点击item,的确可以选中不带后缀名的字符串内容,但无法编辑,点击弹出的虚拟键盘输入内容就会报异常闪退

我不知道应该怎么做,或者说我该怎么实现这样的效果

 @Override
    public View getView( int position, View convertView, ViewGroup parent) {
        mPosition =position;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.mEditView = (EditText) convertView.findViewById(R.id.id_tv_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.mEditView.setText("" + mDatas.get(position));
        viewHolder.mEditView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View arg0, boolean hasFocus) {

                if (hasFocus) {
                    viewHolder.mEditView.setSelection(0, mDatas.get(mPosition).lastIndexOf('.'));
                } else {

                }

            }
        });
        return convertView;
    }

报错如下

 08-05 11:04:02.452: E/AndroidRuntime(16670): FATAL EXCEPTION: main
08-05 11:04:02.452: E/AndroidRuntime(16670): Process: com.crow.shareupload, PID: 16670
08-05 11:04:02.452: E/AndroidRuntime(16670): java.lang.IndexOutOfBoundsException: setSpan (28 ... 28) ends beyond length 5
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1018)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:607)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.text.Selection.setSelection(Selection.java:78)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.EditText.setSelection(EditText.java:92)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at com.crow.shareupload.MyAdapter$2.onFocusChange(MyAdapter.java:72)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.onFocusChanged(View.java:5258)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.TextView.onFocusChanged(TextView.java:7921)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.handleFocusGainInternal(View.java:5014)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.requestFocusNoSearch(View.java:7724)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.requestFocus(View.java:7703)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.requestFocus(View.java:7670)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.requestFocus(View.java:7649)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.ListView.layoutChildren(ListView.java:1746)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.AbsListView.onLayout(AbsListView.java:2148)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.layout(View.java:15686)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewGroup.layout(ViewGroup.java:4967)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.layout(View.java:15686)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewGroup.layout(ViewGroup.java:4967)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.layout(View.java:15686)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewGroup.layout(ViewGroup.java:4967)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:494)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.layout(View.java:15686)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewGroup.layout(ViewGroup.java:4967)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.View.layout(View.java:15686)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewGroup.layout(ViewGroup.java:4967)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2076)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1833)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1058)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5796)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.Choreographer.doFrame(Choreographer.java:550)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.os.Handler.handleCallback(Handler.java:739)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.os.Handler.dispatchMessage(Handler.java:95)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.os.Looper.loop(Looper.java:211)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at android.app.ActivityThread.main(ActivityThread.java:5333)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at java.lang.reflect.Method.invoke(Native Method)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at java.lang.reflect.Method.invoke(Method.java:372)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
08-05 11:04:02.452: E/AndroidRuntime(16670):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

查看全部
suyoung21
suyoung21
2015/08/05 03:15
  • exception
  • editview
  • android
  • list
  • 异常
  • 点赞
  • 收藏
  • 回答
    私信

2个回复