アプリを閉じることを確認するダイアログを表示するときに、次のことで行き詰まりました。アプリは適切に閉じることができますが、logcat ではページ全体が赤くなっています。私はウェブで調査しましたが、ダイアログを作成して表示する必要があると言う人もいます。
コード:
@Override
public void onBackPressed()
{
final Dialog dialog1 = new Dialog(First.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog1.setContentView(R.layout.alert_dialog_quit_with_email);
dialog1.setCancelable(true);
dialog1.show(); // LINE 323
TextView thankyou = (TextView) dialog1.findViewById(R.id.thankyou);
TextView Title_V1 = (TextView) dialog1.findViewById(R.id.Title_V1);
Button alert_cancel = (Button) dialog1.findViewById(R.id.button_cancel);
Button alert_quit = (Button) dialog1.findViewById(R.id.button_ok);
Button button_email = (Button) dialog1.findViewById(R.id.button_emailll);
alert_cancel.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
dialog1.dismiss();
return;
}
});
alert_quit.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
First.this.finish();
}
});
button_email.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
View view1 = getLayoutInflater().inflate(R.layout.first, null);
button_Email_click(view1);
}
});
}
ログキャット:
09-29 23:33:45.450: E/WindowManager(27052): Activity com.abc.abc.First has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42cc5de0 that was originally added here
09-29 23:33:45.450: E/WindowManager(27052): android.view.WindowLeaked: Activity com.abc.abc.First has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42cc5de0 that was originally added here
09-29 23:33:45.450: E/WindowManager(27052): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:412)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:312)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.Window$LocalWindowManager.addView(Window.java:554)
09-29 23:33:45.450: E/WindowManager(27052): at android.app.Dialog.show(Dialog.java:277)
09-29 23:33:45.450: E/WindowManager(27052): at com.abc.abc.First.onBackPressed(First.java:323)
09-29 23:33:45.450: E/WindowManager(27052): at android.app.Activity.onKeyUp(Activity.java:2192)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.KeyEvent.dispatch(KeyEvent.java:2729)
09-29 23:33:45.450: E/WindowManager(27052): at android.app.Activity.dispatchKeyEvent(Activity.java:2431)
09-29 23:33:45.450: E/WindowManager(27052): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2009)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3942)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3890)
09-29 23:33:45.450: E/WindowManager(27052): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3019)
09-29 23:33:45.450: E/WindowManager(27052): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 23:33:45.450: E/WindowManager(27052): at android.os.Looper.loop(Looper.java:137)
09-29 23:33:45.450: E/WindowManager(27052): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-29 23:33:45.450: E/WindowManager(27052): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 23:33:45.450: E/WindowManager(27052): at java.lang.reflect.Method.invoke(Method.java:511)
09-29 23:33:45.450: E/WindowManager(27052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-29 23:33:45.450: E/WindowManager(27052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-29 23:33:45.450: E/WindowManager(27052): at dalvik.system.NativeStart.main(Native Method)
質問:
と書こうとしましたdialog1.create().show();
が、 に赤で下線が引かれ、.create()
と説明されThe method create() is undefined for the type Dialog
ます。
終了ボタンを押したときにのみ赤いログキャットが表示されることを発見しました...ダイアログが表示されますが、アクティビティが閉じられているためですか? II は既に dialog1 を宣言しています...これをどのように変更できますか? ありがとう!