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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:39:14+00:00 2026-05-27T05:39:14+00:00

I am opening an AlertDialog to present the user a text input in order

  • 0

I am opening an AlertDialog to present the user a text input in order to name a new item. This works fine the first time it opens. But the second time I click the button that launches the dialog, the app crashes. I get this error:

12-02 16:01:04.205: E/AndroidRuntime(515): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I’m not sure what this means or where I would call this removeView().

Here is my code:

public class ShoppingList extends Activity implements OnClickListener{

        private AlertDialog.Builder m_alert;
        private Context m_context;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.shopping_list);
            m_context = getApplicationContext();
            LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.add_shopping_list, (ViewGroup) findViewById(R.id.layout_root));
            m_alert = new AlertDialog.Builder(ShoppingList.this);
            //final EditText input = new EditText(this);
            //m_alert.setView(input);
            m_alert.setView(layout);
            final EditText input = (EditText)layout.findViewById(R.id.new_sl_name);
            m_alert.setPositiveButton(R.string.add_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString().trim();
                    Toast.makeText(m_context, value,
                            Toast.LENGTH_SHORT).show();
                    m_alert.create();
                }
            });

            m_alert.setNegativeButton(R.string.cancel_button,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                        m_alert.create();
                    }
                }
            );

            // Add Button. . .
            Button addButton = (Button)findViewById(R.id.add_sl_button);
            addButton.setOnClickListener(this);
        }

        public void onClick(View v) {
            if(!this.isFinishing())
                m_alert.show();
        }
    }
  • 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-27T05:39:15+00:00Added an answer on May 27, 2026 at 5:39 am

    m_alert.create() is called after clicking on the positive and negative buttons. What this does, is create the dialog again.

    Use m_alert.dismiss() instead, so your dialog is dismissed, and you can use it again later

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

Sidebar

Related Questions

Opening a public page from browser works fine. Downloading same page using WebClient throws
I'm opening a text file and removing the first line to prepare it for
I'm opening an Activity using this: startActivity(new Intent(Parent.this, Child.class)); And on the child, I
in Qt im opening QDialog windows each time i click some item im doing
Why is this not opening in a new window? <a href=http://www.authorsden.com/visit/viewwork.asp?id=49784&AuthorID=157940> <img src=authors_den.jpg target=blank
When opening a client against a db40 server it seems to expect a user
When opening new buffer it VIM, I type: new /path/to/fi If I hit tab
Javascript run at page opening or later by user action like clicking a button
I am trying to show in an android AlertDialog some text and some words
On opening a new terminal window (Mac OSX 10.7.2) and entering rails , I

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.