我有弹出窗口。在弹出窗口中有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?
如何解决这个问题?
答案 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) {
}