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.java: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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to