我有AlertDialog
它工作正常,但我注意到它在我放置的行中标记了一个错误dialog.show ();
我不知道如何解决它。
IngresarAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder mBuilder=new AlertDialog.Builder(InicioSesion_Principal.this);
View Mview= getLayoutInflater().inflate(R.layout.zona_restrigida,null);
final EditText claveAdmin=(EditText)Mview.findViewById(R.id.Clave_proveedor);
Button EntrarClaveAdmin=(Button)Mview.findViewById(R.id.Ingresar_clave_proovedor);
EntrarClaveAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!claveAdmin.getText().toString().isEmpty()){
Intent intent=new Intent(getApplicationContext(), menu_administrador.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
else {
Toast.makeText(InicioSesion_Principal.this,"Clave incorrecta",Toast.LENGTH_SHORT).show();
}
}
});
mBuilder.setView(Mview);
AlertDialog dialog=mBuilder.create();
dialog.show();
}
});
这是dialog.show();
中显示的错误
它不会随时关闭应用程序,但我该如何解决?
android.view.WindowLeaked: Activity com.tienda.app.aplicaciontienda.Iniciar_Sesion_3.InicioSesion_Principal has leaked window com.android.internal.policy.PhoneWindow$DecorView{245d004 V.E...... R......D 0,0-683,503} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:375)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:319)
at com.tienda.app.aplicaciontienda.Iniciar_Sesion_3.InicioSesion_Principal$3.onClick(InicioSesion_Principal.java:119)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
答案 0 :(得分:1)
尝试使用dialog.create().show();
我遇到了同样的问题。
答案 1 :(得分:0)
你需要调用.dismiss();
if(dialog != null)
dialog.dismiss();