使用EditText的Android列表视图

时间:2016-10-08 15:31:27

标签: android listview android-edittext

我有viewPager->Listview->Multiple Views(EditText, TextViewes).这样的结构有时当我尝试使用EditText时,键盘不会显示。之后我尝试再次点击它并获得例外。 有 myView 图片
Listview有下一个参数

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grey"
        android:scrollingCache="false"
        android:animationCache="false"
        android:descendantFocusability="afterDescendants">
    </ListView>

这样我创建了EdditText

    private View createView(LayoutInflater inflater, int inputType, String answer, String u_answer,
                        boolean activate, final int id){//, ViewGroup.LayoutParams params){
    final View view = inflater.inflate(R.layout.custom_edit_text, null, false);                 //generate EditTextView
    final EditText edit = (EditText) view.findViewById(R.id.edit);
    TextView text = (TextView) view.findViewById(R.id.hint);
    if(answer.length() > 0)
        text.setText(answer);
    else text.setVisibility(View.GONE);
        edit.setInputType(inputType);                                                               //set input Type
        edit.setHint("Enter answer here...");                                                       //add hint
        edit.setId(id);

        setEditLength(edit,question.getType());                                            //set editText height WRAP_CONTENT
    if(u_answer != null){                                                                         //if user answers exists
        edit.setText(u_answer);                                                                 //set data
        edit.setEnabled(activate);                                                              //set Edit active or not
    }
    editables.add(edit);
    return  view;
}

我得到了这样的错误

Process: com.android.acusurvey, PID: 14874
                  android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
                      at android.view.ViewRootImpl.setView(ViewRootImpl.java:696)
                      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:289)
                      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
                      at android.widget.PopupWindow.invokePopup(PopupWindow.java:1153)
                      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:978)
                      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:942)
                      at com.meizu.widget.MagnifierPopupWindow.showMagnifier(MagnifierPopupWindow.java:106)
                      at android.widget.Editor$MzInsertionPointCursorController.update(Editor.java:5567)
                      at android.widget.Editor$MzInsertionPointCursorController.show(Editor.java:5571)
                      at android.widget.Editor.performLongClickMz(Editor.java:5290)
                      at android.widget.TextView.performLongClick(TextView.java:9126)
                      at android.view.View$CheckForLongPress.run(View.java:20357)
                      at android.os.Handler.handleCallback(Handler.java:815)
                      at android.os.Handler.dispatchMessage(Handler.java:104)
                      at android.os.Looper.loop(Looper.java:194)
                      at android.app.ActivityThread.main(ActivityThread.java:5824)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)

这是什么意思?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

尝试在editText上使用requestFocus(),如

editText.requestFocus()