Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Alert Dialog - Specified child already has a parent - on 2nd attempt
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aaron Buckner  
View profile  
 More options Feb 17 2011, 3:40 pm
From: Aaron Buckner <nagm...@gmail.com>
Date: Thu, 17 Feb 2011 12:40:21 -0800 (PST)
Local: Thurs, Feb 17 2011 3:40 pm
Subject: Alert Dialog - Specified child already has a parent - on 2nd attempt

The following code seems to work just fine the first time its used in the
app but when the user goes to hit the button that calls this Alert Dialog a
second time it creates a Force Close with this as the gist of the logcat
(full at the bottom): "The specified child already has a parent. You must
call removeView() on the child's parent first."

        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        final EditText input = new EditText(this);

        alert.setTitle("Mileage");
        alert.setMessage("Set your mileage");

        alert.setView(input);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int whichButton) {
 String value = input.getText().toString();
SharedPreferences prefs = getSharedPreferences("myDataStorage",
MODE_PRIVATE);
        Editor mEditor = prefs.edit();
        mEditor.putString("mileage", value);
            mEditor.commit();
            UpdateMileage();
            dialog.dismiss();

}
});

        alert.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {  

         public void onClick(DialogInterface dialog, int whichButton) {  
         dialog.cancel();
         dialog.dismiss();
         }  
        });

        //Update Button
        ImageButton UpdateBtn = (ImageButton)
findViewById(R.id.myride_update);
        UpdateBtn.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         alert.show();
         UpdateMileage();
         return;
         }
        });

///////////// Stack Trace /////////////
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):
java.lang.IllegalStateException: The specified child already has a parent.
You must call removeView() on the child's parent first.
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.view.ViewGroup.addView(ViewGroup.java:1871)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.view.ViewGroup.addView(ViewGroup.java:1851)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
com.android.internal.app.AlertController.setupView(AlertController.java:365 )
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
com.android.internal.app.AlertController.installContent(AlertController.jav a:206)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.app.AlertDialog.onCreate(AlertDialog.java:251)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.app.Dialog.dispatchOnCreate(Dialog.java:307)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.app.Dialog.show(Dialog.java:225)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.app.AlertDialog$Builder.show(AlertDialog.java:812)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
com.ceistudios.android.application.Dashboard$14.onClick(Dashboard.java:298)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.view.View.performClick(View.java:2501)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.view.View$PerformClick.run(View.java:9107)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.os.Handler.handleCallback(Handler.java:587)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.os.Handler.dispatchMessage(Handler.java:92)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.os.Looper.loop(Looper.java:123)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
android.app.ActivityThread.main(ActivityThread.java:3812)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
java.lang.reflect.Method.invokeNative(Native Method)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
java.lang.reflect.Method.invoke(Method.java:507)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 841)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-17 15:28:09.560: ERROR/AndroidRuntime(2503):     at
dalvik.system.NativeStart.main(Native Method)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Buckner  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 1:58 pm
From: Aaron Buckner <nagm...@gmail.com>
Date: Mon, 21 Feb 2011 10:58:12 -0800 (PST)
Local: Mon, Feb 21 2011 1:58 pm
Subject: Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

Can anyone give me any ideas here this is really frustrating I can't think
of any other way to implement this and I have to assume the user would mess
up and need to reach this dialog again.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Anderson  
View profile  
 More options Feb 21 2011, 2:07 pm
From: Justin Anderson <magouyaw...@gmail.com>
Date: Mon, 21 Feb 2011 12:07:50 -0700
Local: Mon, Feb 21 2011 2:07 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

What method is this code in?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Buckner  
View profile  
 More options Feb 21 2011, 2:18 pm
From: Aaron Buckner <nagm...@gmail.com>
Date: Mon, 21 Feb 2011 11:18:21 -0800 (PST)
Local: Mon, Feb 21 2011 2:18 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

Its all in the main method I have, part of the onCreate. Should I put it
outside the onCreate section?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sunil Lakhiyani  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 2:23 pm
From: Sunil Lakhiyani <sunillakhiy...@gmail.com>
Date: Mon, 21 Feb 2011 11:23:28 -0800
Local: Mon, Feb 21 2011 2:23 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

please refer this link

http://www.androidpeople.com/android-alertdialog-example/
<http://www.androidpeople.com/android-alertdialog-example/> and

http://www.tutorialforandroid.com/2009/01/displaying-alertdialog-in-a...

<http://www.tutorialforandroid.com/2009/01/displaying-alertdialog-in-a...>this
will help you out.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Buckner  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 3:11 pm
From: Aaron Buckner <nagm...@gmail.com>
Date: Mon, 21 Feb 2011 12:11:19 -0800 (PST)
Local: Mon, Feb 21 2011 3:11 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

Ok, well those helped out to a point... they helped me narrow down the line
of code that is causing the problem...

"alert.setView(input);"

If I comment it out the dialog opens as much as I need it to, of course that
also prevents the user from being able to enter any input in...

which is called initiated here:
final EditText input = new EditText(this);

and called here:
String value = input.getText().toString();

All of which is shown in the original code block for full context, Is there
something I have to do in order to get the view to remove itself or recycle?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sunil Lakhiyani  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 3:24 pm
From: Sunil Lakhiyani <sunillakhiy...@gmail.com>
Date: Mon, 21 Feb 2011 12:24:29 -0800
Local: Mon, Feb 21 2011 3:24 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

http://stackoverflow.com/questions/3968170/android-prompt-users-input...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Anderson  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 3:27 pm
From: Justin Anderson <magouyaw...@gmail.com>
Date: Mon, 21 Feb 2011 13:27:17 -0700
Local: Mon, Feb 21 2011 3:27 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

Whenever I create dialogs, I use onCreateDialog() and let the Activity
handle creation...
http://developer.android.com/reference/android/app/Activity.html#onCr...

To display the dialog use showDialog()...
http://developer.android.com/reference/android/app/Activity.html#show...

This lets the activity handle creating your dialog (and caches it)... Then
you can show it as many times as you want without a problem.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Buckner  
View profile  
 More options Feb 21 2011, 10:38 pm
From: Aaron Buckner <nagm...@gmail.com>
Date: Mon, 21 Feb 2011 19:38:44 -0800 (PST)
Local: Mon, Feb 21 2011 10:38 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

I follow the concept but I always have problems converting dev.android.com
documentation to real world use... can you show me some code to create an
activity managed dialog or point me to an online example. I'm looking around
and not finding very many examples (none that seem to work)... Thanks to
everyone that has looked at this and helped so far.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dianne Hackborn  
View profile   Translate to Translated (View Original)
 More options Feb 21 2011, 11:19 pm
From: Dianne Hackborn <hack...@android.com>
Date: Mon, 21 Feb 2011 20:19:13 -0800
Local: Mon, Feb 21 2011 11:19 pm
Subject: Re: [android-developers] Re: Alert Dialog - Specified child already has a parent - on 2nd attempt

API demos has a sample of creating a bunch of different alert dialogs as
managed dialogs:

http://developer.android.com/resources/samples/ApiDemos/src/com/examp...

On Mon, Feb 21, 2011 at 7:38 PM, Aaron Buckner <nagm...@gmail.com> wrote:
> I follow the concept but I always have problems converting dev.android.comdocumentation to real world use... can you show me some code to create an
> activity managed dialog or point me to an online example. I'm looking around
> and not finding very many examples (none that seem to work)... Thanks to
> everyone that has looked at this and helped so far.

>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »