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(); } });
///////////// 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)
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.
On Mon, Feb 21, 2011 at 11:58 AM, Aaron Buckner <nagm...@gmail.com> wrote: > 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 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
On Mon, Feb 21, 2011 at 11:18 AM, Aaron Buckner <nagm...@gmail.com> wrote: > all in the main method I have, part of the onCreate. Should I put it > outside the onCreate section?
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?
On Mon, Feb 21, 2011 at 12:11 PM, Aaron Buckner <nagm...@gmail.com> wrote: > 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);
On Mon, Feb 21, 2011 at 1:11 PM, Aaron Buckner <nagm...@gmail.com> wrote: > 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 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
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.
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
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.