0

Androidで最初のものを選択した後、AlertDialogを表示するのに助けが必要です。

問題は、2 番目のオプションを表示するオプションの選択が、アプリケーションの終了結果に依存する場合です。

これが私がやったことです。

private void showMenu()
{
    final CharSequence[] items = {"Option1", "Option2", "Option3"};

    final int[] result = new int[1];
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Options");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            switch (item)
            {
                case 0:
                {
                    //dosomething
                    break;
                }
                default:
                {
                    showSecond(item);
                    break;
                }
            }
        }
    });
    AlertDialog alert = builder.create();
   alert.show();
}
    private void showSecond(int c)
    {
        switch (c)
        {
            case 1:
            {

                break;
            }case 2:
            {
                AlertDialog.Builder builder=   new AlertDialog.Builder(context)
                                .setMessage("Are you sure you want to exit?")
                                .setCancelable(false)
                                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        //dosomething
                                    }
                                })
                                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();
            }

            break;
        }
    }

OnDismisListener も試しました

alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
            ConfirmUninstalling(result[0]);
        }
    });

でも同じこと

スローされた例外

09-16 10:09:46.561      822-822/com.android.exchange E/ActivityThread﹕ Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c4b8 that was originally bound here
        android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c4b8 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1418)
        at android.app.ContextImpl.bindService(ContextImpl.java:1407)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
        at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
        at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
09-16 10:09:46.652      822-822/com.android.exchange E/StrictMode﹕ null
        android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c4b8 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1418)
        at android.app.ContextImpl.bindService(ContextImpl.java:1407)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
        at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
        at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
09-16 10:09:46.751      306-578/system_process W/ActivityManager﹕ Unbind failed: could not find connection for android.os.BinderProxy@4104d5b0
09-16 10:09:46.782      822-822/com.android.exchange E/ActivityThread﹕ Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c110 that was originally bound here
        android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c110 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1418)
        at android.app.ContextImpl.bindService(ContextImpl.java:1407)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
        at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
09-16 10:09:46.792      822-822/com.android.exchange E/StrictMode﹕ null
        android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d3c110 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1418)
        at android.app.ContextImpl.bindService(ContextImpl.java:1407)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
        at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
4

1 に答える 1