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 7837627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:45:29+00:00 2026-06-02T14:45:29+00:00

I have two layouts and I am inflating it one after another ,I want

  • 0

I have two layouts and I am inflating it one after another ,I want to dismiss previous view and inflate another but the view is shifted to the background ,hence both the dialogs are present.I would like to dismiss the dialog which is in the background.
I have tried following fixes:

1.dialog.dismiss(); — not working

2.view.setVisibility(View.GONE); — Title of the dialog still remains along with dialog.

I am attaching the entire code.Please let me know how to resolve this.Thanks.

menuproject.java

        package com.menuproject;

        import android.app.Activity;
        import android.app.AlertDialog;
        import android.os.Bundle;
        import android.view.LayoutInflater;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.view.View;
        import android.view.View.OnClickListener;
        import android.widget.Button;

        public class menuproject extends Activity {
            /** Called when the activity is first created. */

            AlertDialog.Builder dialog;
            AlertDialog.Builder dialog2;
            private AlertDialog alert = null;
            private AlertDialog alert2 = null;
            View updatedialog;
            View updatedialog2;

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

            }

            protected void layoutsecond() {
                // TODO Auto-generated method stub
                this.dialog2 = new AlertDialog.Builder(this);
                this.dialog2.setTitle("Update");

                LayoutInflater layoutInflater = LayoutInflater.from(this);
                updatedialog2 = layoutInflater.inflate(R.layout.updatedialog2, null);

                this.dialog2.setView(updatedialog2);
                alert2 = this.dialog2.create();
                this.dialog2.show();

            }

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                // TODO Auto-generated method stub
                MenuItem mi = menu.add(1, 1, 1, "My Menu1");
                mi.setIcon(getResources().getDrawable(R.drawable.icon));

                return super.onCreateOptionsMenu(menu);
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {

                switch (item.getItemId()) {
                case 1:

                    layoutfirst();

                    Button b = (Button) updatedialog.findViewById(R.id.Button11);
                    b.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub

                            // updatedialog.setVisibility(View.GONE);

                            // alert.dismiss();

                            layoutsecond();

                        }
                    });

                    break;

                }
                return super.onOptionsItemSelected(item);
            }

            private void layoutfirst() {
                // TODO Auto-generated method stub

                this.dialog = new AlertDialog.Builder(this);
                this.dialog.setTitle("Update");
                // this.dialog.setMessage("");

                LayoutInflater layoutInflater = LayoutInflater.from(this);
                updatedialog = layoutInflater.inflate(R.layout.updatedialog, null);

                this.dialog.setView(updatedialog);
                alert = this.dialog.create();
                this.dialog.show();

            }

        }

main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    </LinearLayout>

updatedialog.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView02" android:layout_width="fill_parent" 
        android:layout_height="fill_parent" android:fillViewport="true">

<LinearLayout
    android:id="@+id/liner1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >
        <requestFocus></requestFocus>

        <Button
            android:id="@+id/Button11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@android:drawable/ic_menu_call"
            android:text="Update Tel" />

        <Button
            android:id="@+id/Button10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@android:drawable/ic_menu_call"
            android:text="Update Address" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </View>

</LinearLayout>
</ScrollView>

updatedialog2.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView021" android:layout_width="fill_parent" 
        android:layout_height="fill_parent" android:fillViewport="true">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >
        <requestFocus></requestFocus>

        <Button
            android:id="@+id/Button01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@android:drawable/ic_menu_call"
            android:text="Update Mobile" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </View>

</LinearLayout>
</ScrollView>
  • 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-02T14:45:33+00:00Added an answer on June 2, 2026 at 2:45 pm

    Have you tried alert.setContentView(inflated_layout) instead dialog.setView(view_name)

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

Sidebar

Related Questions

I have two layouts(xml files) and I want to flip from one page to
I have a single view with two custom layouts, one for Landscape and one
I have two layouts, one is the main layout inside which I am including
I have two Android applications with a similar functionality but different drawables and layouts.
here in above screen, i have two linear layouts, one for two TextView and
I have two relative layouts that are currently displayed one below the other. I
I have two layouts for one activity like layout-port and layout-land, with different designs.
I'm developing a application with CakePHP, and I have two layouts: one for the
I have two relative layouts together, and I want to set an Image (drawable
I have two layouts one for portrait one for landscape. For portrait I have

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.