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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:22:33+00:00 2026-05-27T11:22:33+00:00

Immediate help needed!! The code used to work fine, but after a while I

  • 0

Immediate help needed!! The code used to work fine, but after a while I noticed rating doesnt work anymore and gives "the specified child already has a parent, call removeView() first..." on thealertDialog.show();` line:

///// Rating bar initialising
    Context mContext = ShowActivity.this;
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.custom_rate_dialog, (ViewGroup) findViewById(R.id.layout_root));

    final RatingBar rating_indicator = (RatingBar)findViewById(R.id.rating_bar_cafe_indicator);
    final float current_rating = (float)mDbHelper.getInt(mRowId, type, RATE_COLUMN);
    rating_indicator.setRating(current_rating);


    rateDialogBuilder = new AlertDialog.Builder(ShowActivity.this);
    rateDialogBuilder.setView(layout);
    rateDialogBuilder.setCancelable(false);
    rateDialogBuilder.setIcon(R.drawable.rate_star_med_on);
    rateDialogBuilder.setTitle("RATE IT!");
    rateDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            rating_indicator.setRating(mDbHelper.getInt(mRowId, type, RATE_COLUMN));
            ((ViewGroup)layout.getParent()).removeView(layout);
            dialog.cancel();
        }
    });

    ratingText = (TextView) layout.findViewById(R.id.rate_text);
    rating = (RatingBar) layout.findViewById(R.id.rating_bar_cafe);
    rating.setRating(current_rating);
    rating.setStepSize(1);
    rating.setOnRatingBarChangeListener(ShowActivity.this);

    if ((int)current_rating != 0) ratingText.setText("Your rating: " + (int)current_rating); 

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

        public void onClick(View view) {

            AlertDialog alertDialog = rateDialogBuilder.create(); 
            alertDialog.show();

        }
    });

    //////

Strange thing, if I call removeAllViews() or removeView() just before alertDialog.show(); it does not crash but opens messed up dialogue where I can see both the rating and the current activity or smth. Also the problem might be somewhere else in the code because this used to work fine, any ideas what should I look for or how to change this to make it work?

  • 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-27T11:22:33+00:00Added an answer on May 27, 2026 at 11:22 am

    The error you’re getting is that you are adding a View to a parent after it has already been added to a parent.

    Looking at your code, it looks like,

    layout = inflater.inflate(R.layout.custom_rate_dialog, (ViewGroup) findViewById(R.id.layout_root));
    

    adds custom_rate_dialog to you layout_root. Then, you’re adding it to another parent when you do rateDialogBuilder.setView(layout);

    If you’re just trying to inflate that layout to set it as the View for the Dialog then just do

    layout = inflater.inflate(R.layout.custom_rate_dialog, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed some help in trying to optimize this code portion ... Basically here's
While compiling the following code {\centering {\includegraphics[scale=.5]{splash.eps}} \caption{Splash Screen} \par} \end{figure} Splash screen is
we needed to convert CVS to GIT yesterday. Everything went fine except that I
With the help of one of StackOverflow's I beat one problem, but now I
Can anybody help with the above. We're using a CMS product called Immediacy, which
The Immediate Window is an immensely useful tool for debugging applications. It can be
From the Immediate Window in Visual Studio: > Path.Combine(@C:\x, y) C:\\x\\y > Path.Combine(@C:\x, @\y)
It would seem the Immediate window needs some jazzing up ala IntelliSense? Anyone agree/disagree?
how can i get immediate parent of a given element ? $(e.target).parent() ?
Once I've created a variable in the immediate window in C# (VS2008), is there

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.