1
拼錯的單詞我有一個問題與的inputType text
的EditText
定義EditText
像下面這樣的時候:
<EditText
android:id="@+id/text_name"
android:inputType="text"
android:text="some txt"
.
.
./>
這裏inputType
是text
,文本價值"some txt"
其中包含一個拼寫錯誤的詞,它是「txt」。這個EditText包含在一個佈局中,該佈局顯示爲一個彈出窗口。
現在,當一些Button
點擊了Activity
這個佈局POP操作機,字TXT被強調是有錯的話,和任何其他字聚焦在EditText
當鍵盤出現通常並沒有什麼錯誤發生,但在拼錯的單詞對焦時TXT應用程序崩潰,但以下情況除外:
11-09 16:50:02.126: W/dalvikvm(5205): threadid=1: thread exiting with uncaught exception (group=0x40ffc9a8)
11-09 16:50:02.127: W/System.err(5205): android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
11-09 16:50:02.127: W/System.err(5205): at android.view.ViewRootImpl.setView(ViewRootImpl.java:646)
11-09 16:50:02.127: W/System.err(5205): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
11-09 16:50:02.127: W/System.err(5205): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
11-09 16:50:02.127: W/System.err(5205): at android.widget.PopupWindow.invokePopup(PopupWindow.java:993)
11-09 16:50:02.127: W/System.err(5205): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:847)
11-09 16:50:02.128: W/System.err(5205): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:811)
11-09 16:50:02.128: W/System.err(5205): at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2207)
11-09 16:50:02.128: W/System.err(5205): at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2164)
11-09 16:50:02.128: W/System.err(5205): at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2406)
11-09 16:50:02.128: W/System.err(5205): at android.widget.Editor.showSuggestions(Editor.java:1700)
11-09 16:50:02.128: W/System.err(5205): at android.widget.Editor$1.run(Editor.java:1599)
11-09 16:50:02.128: W/System.err(5205): at android.os.Handler.handleCallback(Handler.java:725)
11-09 16:50:02.129: W/System.err(5205): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 16:50:02.129: W/System.err(5205): at android.os.Looper.loop(Looper.java:153)
11-09 16:50:02.129: W/System.err(5205): at android.app.ActivityThread.main(ActivityThread.java:5299)
11-09 16:50:02.129: W/System.err(5205): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 16:50:02.130: W/System.err(5205): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 16:50:02.133: W/System.err(5205): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
11-09 16:50:02.134: W/System.err(5205): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-09 16:50:02.134: W/System.err(5205): at dalvik.system.NativeStart.main(Native Method)
並修復這個bug我必須改變inputType
在EditText
至textNoSuggestions
。
那麼,爲什麼會發生這個問題呢?以及如何使用inputType
作爲text
並處理拼寫錯誤的單詞時沒有任何問題?
而且這是我的編程處理它:
private static PopupWindow pw;
private View layout;
private static ViewGroup vg = (ViewGroup) findViewById(R.id.popup_container);
private void initiate_popup(){
layout = inflater.inflate(R.layout.popup,
vg);
pw = new PopupWindow(layout, 500,
450, true);
pw.setOutsideTouchable(true);
pw.setBackgroundDrawable(new ColorDrawable(
android.graphics.Color.TRANSPARENT));
pw.setTouchInterceptor(on_outside_touch);
pw.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
hideKeyboard();
}
});
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
String name = "some txt";
// Declaring EditText
InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
final EditText text_name = (EditText) layout.findViewById(R.id.text_name);
imm.hideSoftInputFromWindow(text_name.getWindowToken(), 0);
text_name.setText(name);
}
// hide Keyboard method
public void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) ctx
.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); // hide
} else {
ctx.getWindow()
.setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}