How to set DialogFragment’s width and height?

Let’s say I specify the layout of my DialogFragment in an xml layout file named my_dialog_fragment.xml and I specify the layout_width and layout_height values of its root view to a fixed value (e.g. 100dp). I then inflate this layout in my DialogFragment‘s onCreateView(…) method as follows: View view = inflater.inflate(R.layout.my_dialog_fragment, container, false); Sadly, I find … Read more

How to show a dialog to confirm that the user wishes to exit an Android Activity?

I’ve been trying to show a “Do you want to exit?” type of dialog when the user attempts to exit an Activity. However I can’t find the appropriate API hooks. Activity.onUserLeaveHint() initially looked promising, but I can’t find a way to stop the Activity from finishing. 11 Answers 11

Android 1.6: “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”

I’m trying to open a dialog window, but every time I try to open it it throws this exception: Uncaught handler: thread main exiting due to uncaught exception android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application at android.view.ViewRoot.setView(ViewRoot.java:460) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) at android.app.Dialog.show(Dialog.java:238) at android.app.Activity.showDialog(Activity.java:2413) I’m creating it by … Read more

How to create a Custom Dialog box in android?

I want to create a custom dialog box like below I have tried the following things. I created a subclass of AlertDialog.Builder and used a custom Title and Custom Content View and used that but the result was not as expected. Another attempt was to subclass DialogFragment and customize the dialog inside onCreateDialog that but … Read more

How to handle screen orientation change when progress dialog and background thread active?

My program does some network activity in a background thread. Before starting, it pops up a progress dialog. The dialog is dismissed on the handler. This all works fine, except when screen orientation changes while the dialog is up (and the background thread is going). At this point the app either crashes, or deadlocks, or … Read more

How to prevent a dialog from closing when a button is clicked

I have a dialog with EditText for input. When I click the “yes” button on dialog, it will validate the input and then close the dialog. However, if the input is wrong, I want to remain in the same dialog. Every time no matter what the input is, the dialog should be automatically closed when … Read more