EditText setError 在 PopupWindow 中不起作用

2023-12-28

I had popup window具有自定义布局edittext。我试图在以下位置显示错误消息edittext with 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);

这不是关于setError(String error),也许您在错误的时间添加了 PopupWindow。

参考 https://stackoverflow.com/a/8782594/3003823

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

EditText setError 在 PopupWindow 中不起作用 的相关文章

随机推荐

  • WPF MVVM 和视图继承

    我有大约十几个不同的视图 除了它们绑定的属性名称之外 它们几乎完全相同 例如 以下部分形成两个不同的视图
  • Android 版 PayPal MPL 返回错误 ID 589023

    我是 Android 开发新手 当我点击 PayPal 应用程序时 我遇到以下问题paypal登录成功后的支付按钮 它显示类似 ANDROID 589023 的错误 贝宝错误589023具体有这样的含义 如果因货币兑换而舍入小数部分 则可能
  • 如何在Python中将字符串变为大写? [复制]

    这个问题在这里已经有答案了 如何在 Python 3 4 中将字符串转换为全部大写 例如 我想转换 string to STRING 我已经尝试过 upper方法 但它返回 string upper
  • 如何禁用asp.net razor 视图中的旋转按钮?

    在模型类中列名称是public int CTScore get set 在 Razor 视图中我想用它作为 Html EditorFor model gt model CTScore 它显示为编辑器框以及向上 向下箭头旋转按钮 但我不需要显
  • easylist 中的 AD url 列表

    Adblockplus如何使用https easylist downloads adblockplus org easylist txt https easylist downloads adblockplus org easylist t
  • VBA获取连接器“从形状”和“到形状”

    我在 Excel 中有一个流程设计 使用形状 连接器等 我需要的是有一个矩阵 并且每个形状都有所有的前任和所有的后继 在 VBA 中 为此我尝试执行以下操作 我列出了所有连接器 Shapes AutoShapeType 2 对于每一个 我想
  • 如何解决这个问题呢? SVN 1.8.19:E170000:无法识别的 URL 方案

    我想在我的linux服务器 SUSE Linux Enterprise Server 11 上使用svn 并且我安装了svn 1 8 19 但是当我使用 svn update时 出现问题 svn E170000 Unrecognized U
  • 使用 XCopy 将具有精确结构的文件复制到另一个目录中

    我想复制这个文件C Majid File text txt to D Copied C Majid File text txt gt D Copied 我想使用 Xcopy 将该文件及其完整目录复制到D Copied 那么我应该有这样的东西
  • 无法将 FindFileData.cFileName 转换为字符串

    我取得了很大的进展 但有两个问题几天来一直困扰着我 最大的就是我想保存FindFileData cFileName作为字符串 但我不能 有什么帮助吗 我从这里复制了这个 如何将wstring转换为字符串 https stackoverflo
  • 拟合 beta 分布时出错:函数 mle 无法估计参数,错误代码为 100

    我正在尝试使用fitdist 函数从fitdistrplus包以使我的数据适合不同的分布 假设我的数据如下所示 x c 1 300000 1 220000 1 160000 1 300000 1 380000 1 240000 1 1500
  • 使用 noscript 嵌入额外的样式

    我有一个 XHTML 严格页面 其中有一个由 Javascript 控制的不可见 div 通过脚本和鼠标悬停事件将 div 设置为透明且可见 以使 div 在悬停时不透明 当有人使用没有 javascript 的浏览器 或带有 noscri
  • 如何从 JSP 访问 JavaScript 中的 Java 对象 [重复]

    这个问题在这里已经有答案了 我在 JSP 中有一个下拉框 列出了一个 Java 对象 通过 MVC 控制器的 addAttribute 访问该对象 现在 从下拉框中选择一个选项时 我想在 div 中显示所选员工的其他详细信息 例如 empl
  • Spring数据Redis HGETALL操作

    我在用Redis作为我的 Spring Web 应用程序的数据存储并使用Spring Data Redis作为我的客户与之互动Redis 我在用HashMap存储一个具有多个字段的对象 我可以将所有字段放入Redis立即使用DefaultR
  • iPhone 中可扩展的 tableView

    我想做这种类型的可展开 可折叠表视图 如图所示 有类别和子类别 例如 健康与美丽 是一个类别 当我单击此单元格时 它会打开子类别 如下图所示 那么如何制作这种类型的表格视图呢 请建议我 最后 我在下面得到了两个非常有用的帮助链接 其中准确描
  • 即使添加 SSH 密钥后,Github 上的身份验证仍失败

    当我尝试将代码推送到我的存储库时 我收到 fatal Authentication Failure 我也在我的 github 帐户上添加了公钥 当我做 ssh i email protected cdn cgi l email protec
  • Firebase 托管 - 功能重写定价

    如果你使用Firebase 托管将请求定向到云功能通过重写 通过 托管的请求流量是否会计入 Firebase 托管GB 已转移 忽略云功能的计费 换句话说 Do Firebase 托管当请求到来时 函数重写本身要花钱吗 需要明确的是 明显地
  • HTTP 标头中缺少 Spring WebServiceTemplate SOAPAction

    我在通过 Spring ws WebServiceTemplate 调用 SOAP 1 2 WebService 时遇到困难 发出的请求在 Http 标头中缺少 SOAPAction 并且服务器抛出错误 无法处理没有有效操作参数的请求 请提
  • 添加 2 个时间值的混乱

    基本上这一切都让我感到沮丧 我是编程新手 所以如果我问了一个愚蠢的问题 我深表歉意 我的数据库中存储了一个 MySQL time 我想将此时间添加到当前时间以建立目标时间 持续时间为 06 00 00 MySQL时间 length strt
  • laravel中的双冒号是什么意思

    例子 Auth guard guard gt guest 我不明白双冒号 表示法在 Laravel 框架中的含义 从http php net manual en language oop5 paamayim nekudotayim php
  • EditText setError 在 PopupWindow 中不起作用

    I had popup window具有自定义布局edittext 我试图在以下位置显示错误消息edittext with setError方法 但它给出了以下异常 android view WindowManager BadTokenEx