我的popup window
自定义布局有edittext
。我正在尝试使用edittext
方法在setError
中显示错误消息,但它会给出以下异常。
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@211ffd68 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:579)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1104)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1008)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:968)
at android.widget.Editor.showError(Editor.java:334)
at android.widget.Editor.setError(Editor.java:355)
at android.widget.TextView.setError(TextView.java:4654)
at android.widget.TextView.setError(TextView.java:4639)
at com.ebusiness.worldofjobs.helpers.HelperEditText.isEmailValid(HelperEditText.java:38)
at com.ebusiness.worldofjobs.activities.LoginActivity$4$2.onClick(LoginActivity.java:149)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
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:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
弹出窗口:
View popupView = LayoutInflater.from(LoginActivity.this).inflate(R.layout.popup_reset_password, null);
EdiText etSmaple = (EditText) popupView.findViewById(R.id.etSmample);
Button buttonSample = (Button) popupView.findViewById(R.id.buttonSample);
final PopupWindow popupWindow = new PopupWindow(popupView, 600, 400);
popupWindow.setFocusable(true);
buttonSample.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Here's the exception raising
etSample.setError("Nothing...");
}
});
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);