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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:53:48+00:00 2026-06-15T16:53:48+00:00

I have this piece of code to display an alert dialog when an item

  • 0

I have this piece of code to display an alert dialog when an item in a listView is clicked; all worked ok until I added a checkbox preference that should enable another dialog to enter a text string (to be used later on).

AlertDialog.Builder helpBuilder = new AlertDialog.Builder(MyActivity.this);

helpBuilder.setIcon(android.R.drawable.ic_dialog_info);
adb.setTitle("title");
adb.setMessage("message");

        helpBuilder.setPositiveButton("positive", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                        boolean fileRenameEnabled = settings.getBoolean("text_view", false);
                        if (fileRenameEnabled == true) {
                            AlertDialog.Builder adb = new AlertDialog.Builder(MyActivity.this);
                            LayoutInflater adbInflater = LayoutInflater.from(MyActivity.this);
                            View inputFilename = adbInflater.inflate(R.layout.dialog_text_view, null);
                            tv = (TextView) inputFilename.findViewById(R.id.tv);
                            tv.setHint("hint");

                            adb.setView(tv);
                            adb.setTitle("New filename");

                            adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    //some code here modifies method1()
                                    method1();
                                }
                            });
                            adb.show();
                        } else {
                            method1();
                        }
                    }
                });

                helpBuilder.setNeutralButton("neutral", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        Checkbox1Enabled = settings.getBoolean("checkbox1", true);
                        if (Checkbox1Enabled == true) {
                            AlertDialog.Builder adb = new AlertDialog.Builder(MyActivity.this);
                            LayoutInflater adbInflater = LayoutInflater.from(MyActivity.this);
                            View info = adbInflater.inflate(R.layout.dialog_checkbox1, null);
                            cb = (CheckBox) info.findViewById(R.id.cb);
                            cb.setChecked(true);
                            adb.setView(info);
                            adb.setTitle("title");
                            adb.setMessage("message");

                            adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (cb.isChecked() == false) {
                                        SharedPreferences.Editor editor = settings.edit();
                                        editor.putBoolean("checkbox1", false);
                                        editor.commit();
                                        Checkbox1Enabled = settings.getBoolean("checkbox1", true);
                                        Log.d(DEBUG_TAG, "Checkbox1Enabled: " + Checkbox1Enabled);
                                    }
                                    method2(); 
                            }
                            });
                            adb.show();
                        } else {
                            method2();
                        }
                    }
                });
                AlertDialog helpDialog = helpBuilder.create();
                helpDialog.show();
            }
});

}

The fact is that I’m doing almost the same thing inside the onClickListener for the neutral button; the only difference is that I’m inflating a textView in the AlertDialog.Builder instead of a checkbox (that works…).

The exception is:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

Any help is much appreciated.
Thanks!

  • 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-15T16:53:49+00:00Added an answer on June 15, 2026 at 4:53 pm

    You’re adding the TextView as the content of the dialog instead of the inflated layout(and the TextView (most likely) already has a parent in the layout that you inflate). It should be:

    View inputFilename = adbInflater.inflate(R.layout.dialog_text_view, null);
    tv = (TextView) inputFilename.findViewById(R.id.tv);
    tv.setHint("hint");
    adb.setView(inputFilename);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code, <div id=event style=display:none;> <!-- initially hidden --> <div
I have this piece of code I'm trying to get to display but no
I have this piece of assembly code to accept a string and display the
I have this HTML piece of code and I want to display:none on the
I have written this piece of CF code to get and display the data
I have this piece of code in a function. I want to print the
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have this piece of code for my images, so the opacity can lower
I have this piece of code which check the last customer_id from the db.

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.