【问题标题】:EditText setError not working in PopupWindowEditText setError 在 PopupWindow 中不起作用
【发布时间】:2016-03-02 08:14:00
【问题描述】:

我有 popup window 的自定义布局,其中有 edittext。我正在尝试使用setError 方法在edittext 中显示错误消息,但它给出了以下异常。

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);

【问题讨论】:

  • 在哪一行出现问题?
  • @ρяσѕρєя K setError("Nothing...")
  • 你在哪个 android 版本上测试这个?
  • @Sushant 在以前的版本上试试这个,比如果冻豆.. 只是为了测试。
  • @Sharp Edge 对不起老兄。但我没有准备好设备或模拟器。

标签: android android-edittext android-popupwindow


【解决方案1】:

这与setError(String error) 无关,可能是您在错误的时间添加了 PopupWindow。

Reference

【讨论】:

  • 请详细说明您的意思是什么时间。我尝试了showAtLocation() 的2 个位置。之前和之后buttonSample 听众。
  • @RockFlower 实际上我是在单击按钮时执行此代码。
猜你喜欢
  • 1970-01-01
  • 2017-01-14
  • 1970-01-01
  • 2012-11-10
  • 2014-01-03
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多