Popup的Editext验证

时间:2015-12-29 05:07:07

标签: android android-edittext

我有弹出窗口。在弹出窗口中有editext。在弹出窗口内点击button时,检查editext为空并在editext上设置错误,同时触摸错误editext时出现此错误

 android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41d33850 is not valid; is your activity running?

如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

在显示Activity之前检查PopupWindow状态。请使用以下代码:

if (!isFinishing()) {
   // Do yout stuffs here...
}

希望这会有所帮助。

答案 1 :(得分:0)

使用此代码

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Reset Password");
    alert.setMessage("Please enter the e-mail address for your account.");
    final EditText email = new EditText(this);
    LinearLayout lay = new LinearLayout(this);
    lay.setOrientation(LinearLayout.VERTICAL);
    email.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    lay.addView(email);
    alert.setView(lay);

    alert.setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
}