Android Edittext键盘问题?

时间:2014-07-11 12:11:14

标签: android keyboard

在其中一个Application Am中使用Edittext编辑数据,有些时候工作正常,有时会出现一些错误(参见下面的错误日志)

 07-11 17:27:40.003: E/SpannableStringBuilder(18003): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 07-11 17:27:40.003: E/SpannableStringBuilder(18003): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 07-11 17:27:40.023: D/AndroidRuntime(18003): Shutting down VM
 07-11 17:27:40.023: W/dalvikvm(18003): threadid=1: thread exiting with uncaught exception (group=0x41838300)
 07-11 17:27:40.023: E/AndroidRuntime(18003): FATAL EXCEPTION: main
 07-11 17:27:40.023: E/AndroidRuntime(18003): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41f6f0b0 is not valid; is your activity running?
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.view.Window$LocalWindowManager.addView(Window.java:547)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.PopupWindow.invokePopup(PopupWindow.java:988)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.PopupWindow.showAtLocation(PopupWindow.java:845)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.PopupWindow.showAtLocation(PopupWindow.java:809)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2147)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2104)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2349)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.Editor.showSuggestions(Editor.java:1647)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.widget.Editor$1.run(Editor.java:1546)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.os.Handler.handleCallback(Handler.java:615)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.os.Handler.dispatchMessage(Handler.java:92)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.os.Looper.loop(Looper.java:137)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at android.app.ActivityThread.main(ActivityThread.java:4745)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at java.lang.reflect.Method.invokeNative(Native Method)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at java.lang.reflect.Method.invoke(Method.java:511)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
 07-11 17:27:40.023: E/AndroidRuntime(18003):   at dalvik.system.NativeStart.main(Native Method)

这是我正在使用的Xml文件

  <EditText
        android:id="@+id/editText_popup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        />

主要活动类是这个

  Another seperateclass = new Another(Mainactivity.this)
  button.setOnClickListener(seperateclass );

这是我的班级功能

 @Override
        public void onClick(View v) {

            LayoutInflater factory = LayoutInflater.from(mainactivity);
            final View deleteDialogView = factory.inflate(R.layout.custom_popup, null);
            final AlertDialog deleteDialog = new AlertDialog.Builder(mainactivity).create();
            deleteDialog.setView(deleteDialogView);
            final EditText input =(EditText)deleteDialogView.findViewById(R.id.editText_popup);

            input.setText(addr3_title);
            input.setSelection(input.getText().length());

  }

Note1:编辑文本显示在弹出对话框中。

1 个答案:

答案 0 :(得分:-1)

从另一个问题:Error : BinderProxy@45d459c0 is not valid; is your activity running? 在对话框还活着的时候,您的活动可能正在完成。尝试像DiscDev那样回答他的答案,确保当对话框可见时活动仍然存在。

if(!((Activity) context).isFinishing())
{
    //show dialog
}