Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:12+00:00 2026-06-13T07:18:12+00:00

I have created a dialog which contains a list view. The onclicklistener for the

  • 0

I have created a dialog which contains a list view. The onclicklistener for the list view dialog then loads a new, inner dialog asking the user to confirm their choice.

Once this is done i want to close both the outer and inner dialog boxes. I am able to close the inner one no problem but am struggling to figure out a way to close the outer dialog which contains a list view from the inner.

An extract of my code is below:

// Display list of sites
                    AlertDialog.Builder builder = new AlertDialog.Builder(
                            this);
                    builder.setTitle("Sites Near Me");

                    ListView modeList = new ListView(this);
                    ArrayList<String> stringArrayList = new ArrayList<String>();

                    for (int i = 0; i < possibleLocaitons.size(); i++) {
                        String currentLocation = possibleLocaitons.get(i)
                                .getName();
                        stringArrayList.add(currentLocation);
                    }

                    ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(
                            this, android.R.layout.simple_list_item_1,
                            android.R.id.text1, stringArrayList);
                    modeList.setAdapter(modeAdapter);

                    // List click listener
                    modeList.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent,
                                View view, int pos, long id) {

                            String site = parent.getItemAtPosition(pos)
                                    .toString();

                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                    LocationActivity.this);

                            // set title
                            alertDialogBuilder.setTitle("");

                            // set dialog message
                            alertDialogBuilder
                                    .setMessage("Check in at " + site + "?")
                                    .setCancelable(false)
                                    .setPositiveButton(
                                            "Yes",
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(
                                                        DialogInterface dialog,
                                                        int id) {
                                                    // Update the database
                                                    UserFunctions us = new UserFunctions();
                                                    us.updateLocation(
                                                            "fish", "888");
                                                    dialog.cancel();


                                                }
                                            })
                                    .setNegativeButton(
                                            "Cancel",
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(
                                                        DialogInterface dialog,
                                                        int id) {
                                                    dialog.cancel();
                                                }
                                            });

                            // create alert dialog
                            AlertDialog alertDialog = alertDialogBuilder
                                    .create();

                            // show it
                            alertDialog.show();
                        }

                    });

                    builder.setView(modeList);
                    final Dialog dialog = builder.create();

                    dialog.show();

                }

Any help greatly appreciated.

Edit:

Here is a screenshot of what I am trying to achieve:

http://dl.dropbox.com/u/57441159/Screenshot_2012-10-21-10-13-21.png

When “yes” is clicked i want to cancel both the “sites near me” and “check in at” dialogs, returning to the map activity in the background. Currently it only cancels “check in at” then returns to “sites near me”. I hope this is more clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:18:13+00:00Added an answer on June 13, 2026 at 7:18 am

    You cannot access this piece of code from alertDialogBuilder’s anonymous onClick() since it is forward referenced

     final Dialog dialog = builder.create();
     dialog.show();
    

    Move it under builder.setTitle("Sites Near Me");. The proceed to dismiss the dialog from a UI thread using activity.runOnUiThread().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some code to popup a confirm dialog if a user tries
I have created a ListView which contains a list of items. Each item in
hello all I have a small dialog which I created dynamically, which has a
I have created a Dialog with two buttons Yes, No, and then I have
I have created an layout which contains the listview. I have added a button
I have created a custom dialog box which requires 3 fields public class Test{
Hey Folks,I have pasted my code here. Dialog.inform contains a 'long' value which is
I have created a JDialog which contains a JComboBox and a panel underneath which
I have created a My custom Dialog which extends org.eclipse.jface.dialogs.Dialog. But whenever it displays,
I have a listview which is filled with data form sqlitedatabase. A list-view element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.