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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:38:45+00:00 2026-06-13T15:38:45+00:00

Im getting this error when trying to implement both onClickListener and onLongClickListener for a

  • 0

Im getting this error when trying to implement both onClickListener and onLongClickListener for a RelativeLayout:

10-19 17:49:31.400: E/AndroidRuntime(30886): FATAL EXCEPTION: main
10-19 17:49:31.400: E/AndroidRuntime(30886): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

This is part of the code:

RelativeLayout meals_layout = (RelativeLayout) view
.findViewById(R.id.meals);      

meals_layout.setOnLongClickListener(new OnLongClickListener() { 
    @Override
    public boolean onLongClick(View v) {

        AlertDialog.Builder builder = new AlertDialog.Builder(
                JournalActivity.this);
        builder.setTitle(R.string.meal_delete); 
        builder.setView(clickView);

        builder.setPositiveButton(R.string.string_delete,
                new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

            }

        });
        builder.setNegativeButton(R.string.string_cancel,
                new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog,
                    int which) {
                // Do nothing
                dialog.dismiss();
            }
        });

        builder.create().show();
        return false;
    }
});

meals_layout.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                JournalActivity.this);
        builder.setTitle(R.string.meal_edit); // al que hacerlo bonito
        builder.setView(clickView);

        builder.setPositiveButton(R.string.string_edit,
                new DialogInterface.OnClickListener() {
        }
    });

        builder.setNegativeButton(R.string.string_cancel,
                new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog,
                    int which) {
                // Do nothing
                dialog.dismiss();
            }
        });


        builder.create().show();

}
});

The first time I open the activity, I can do a longclick as many times as i want. But when I click any other other button (not only the one sentenced here), if I try again to do a longclick… the application crashes.

I will really appreciate your help.
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-13T15:38:47+00:00Added an answer on June 13, 2026 at 3:38 pm

    Each view is only allowed one parent. Apparently clickView already has one, so when you call setView(clickView) it throws the error. One fix is to add:

    ((GroupView) clickView.getParent()).removeView(clickView);
    

    to the beginning of both of your listeners. This will “orphan” clickView so it can be added to the AlertDialog.

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

Sidebar

Related Questions

I'm new to AS3 and I'm getting this error while trying to implement OO
I am trying to implement InAppSettingKit and getting this error: Undefined symbols for architecture
I'm trying to implement adaptive payments but keep getting this weird error. Here's the
I'm getting this error trying to implement the sample WCF Dependency Injection with Unity.
I am getting this error after trying to implement paging support. I am on
I'm getting this error when I'm trying to implement this code. The first code
I am new to php and I am getting this error trying to load
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
I'm getting this error when trying to access my webservice running inside tomcat. Caused
I am getting this error when trying to merge TFS2008. There are no pending

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.