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

  • SEARCH
  • Home
  • 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 7444123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:26:39+00:00 2026-05-29T11:26:39+00:00

I’m writing my first Android application and I have one activity that I’d like

  • 0

I’m writing my first Android application and I have one activity that I’d like to display two separate dialogs:

Dialog A – A simple AlertDialog that shows text and gets dismissed
Dialog B – A “Save As” pop-up with an EditText and Save and Cancel buttons

I’ve found tutorials on creating AlertDialogs and Custom Dialogs and I’ve been able to get each of them to work, but only separately. When I try to put all of the code into a switch/case statement in the onCreateDialog method, the application crashes when the AlertDialog is launched.

Here’s my onCreateDialog code:

@Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        // Display dialog
        case 0:  
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setMessage(messageText);
            alertDialog.setNegativeButton(android.R.string.ok, 
                    new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                }
            });
            return alertDialog.create();    
        // Save As dialog

        case 1: 
            Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.save_as);
            dialog.setTitle("Save as:");

            Button cancel = (Button)findViewById(R.id.cancel);
            cancel.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                }

            });
            return dialog;  
        }
        return null;

    }

Either case will work by itself, but the application crashes when I put both cases in.

Here’s the XML for the custom dialog layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:padding="10dp">

    <TextView 
        android:text="Save this list as:"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <EditText 
        android:id="@+id/list_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:drawable/bottom_bar" 
    android:paddingLeft="4.0dip"
    android:paddingTop="5.0dip" 
    android:paddingRight="4.0dip"
    android:paddingBottom="1.0dip" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
        <Button
           android:id="@+id/save" 
           android:layout_width="0.0dip"
        android:layout_height="fill_parent" 
        android:text="Save"
        android:layout_weight="1.0"
            ></Button>
        <Button
            android:id="@+id/cancel" 
            android:layout_width="0.0dip"
        android:layout_height="fill_parent" 
        android:text="Cancel"
        android:layout_weight="1.0"
            ></Button>

    </LinearLayout>

</LinearLayout>

Should I stick with just one format or the other? I’ve also read that DialogFragments are preferred now, but I haven’t found any good novice-level tutorials on those yet. Any suggestions will be greatly appreciated.

  • 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-05-29T11:26:40+00:00Added an answer on May 29, 2026 at 11:26 am

    I eventually realized that I needed to pass data to and from the dialog, and I am targeting a low API so I just changed the Save As dialog to an Activity, and everything works fine. Learned a lot of limitations of dialogs along the way though….

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

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.