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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:47:44+00:00 2026-05-28T04:47:44+00:00

Following on from another question I have asked I have created a new class

  • 0

Following on from another question I have asked I have created a new class to have an AlertDialog.Builder. This is used in multi classes thoughtout my app. I am creating an object of the class in the class I am using then calling the show() method when needed. This appears correctly.

Trouble I have is as soon as I try and call the show() again I get the following Error :

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

I am not 100% sure where I need to call this removeView or specifc view. Below is the code of the Dialog Class

public class CommentDialog {
    private final Context context;
    private final AlertDialog.Builder builder;    
    private String text;

    private EditText editText;

    public CommentDialog(Context context) {
        this.context = context;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.comment_dialog, null);

        editText = (EditText) layout.findViewById(R.id.comment_text);
        editText.setText(getCommentText());

        builder = new AlertDialog.Builder(context);

        builder.setView(LayoutInflater.from(context).inflate(R.layout.round_comment_dialog, null));
        builder.setTitle(R.string.round_comment_title); 
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {

                               setCommentText(editText.getText().toString());

                           }
                        });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {


                           }
                        });
        builder.create();
    }

    public void setCommentText(String pCommentText) {
        text = pCommentText;
    }

    public String getCommentText() {
        return text;
    }

    public void show() {
        builder.show();
    }


}

Thanks for your Time

EDITTED

added round_comment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dip"
    android:background="@drawable/border_main"
    android:orientation="vertical" >

        <EditText
            android:id="@+id/comment_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:gravity="top|left"
            android:inputType="textMultiLine"
            android:lines="5" >
        </EditText>

</LinearLayout>

EDITTED MK2

Within the main class I am doing the following :

above contructor

private CommentDialog myDialog;

within the oncreate()

myDialog = new CommentDialog(this);

Then on a button press :

case R.id.round_comment_button:
            myDialog.setommentText(comentText);
            myDialog.show();

            roundComentText = myDialog.getRoundCommentText();

            break;
  • 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-28T04:47:45+00:00Added an answer on May 28, 2026 at 4:47 am

    You are better off just having your class extend the Dialog class and building it and then showing it. Of course your views would be created in the constructor of your Dialog class. Because the Dialog does not have a Positive and Negative buttons available, you will have to create your own and set anonymous listeners for your Dialog to listen to them. Everything else should be easy.

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

Sidebar

Related Questions

Following on from a question I posted yesterday about GUIs, I have another problem
this kind of follows on from another question of mine. Basically, once I have
I have the following css from another question: .title {color:#707070;} .username {color:#8DAAB8;} .dateandtime {color:#A5A7AC;}
I found the following AES encryption class from another question here. The class (as
I've got the following code from another question on SO to track the changing
I have enabled GZip compression via web.config with many helps from another question: Enable
This question is in relation to another question asked here: Sorting 1M records I
The following gist: https://gist.github.com/1876791 (borrowed from the demo in this question ) is a
I'm sure this question has already been asked in one form or another, but
Following on from another question on Stack Overflow by a different user, I thought

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.