android-dialog

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

寵の児 提交于 2019-11-26 02:39:38
问题 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. 回答1: In Android 2.0+ this would look like: @Override public void onBackPressed() { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Closing Activity") .setMessage("Are you sure you

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

痴心易碎 提交于 2019-11-26 00:07:52
问题 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 gets into a weird stage where the app does not work at all until all the threads have been killed. How can I handle the screen orientation change gracefully? The sample

Android Activity as a dialog

為{幸葍}努か 提交于 2019-11-25 23:58:48
问题 I have an Activity named whereActity which has child dialogs as well. Now, I want to display this activity as a dialog for another activity. How can I do that? 回答1: To start activity as dialog I defined it like this in AndroidManifest.xml : <activity android:theme="@android:style/Theme.Dialog" /> Use this property inside your activity tag to avoid that your Dialog appears in the recently used apps list android:excludeFromRecents="true" If you want to stop your dialog / activity from being

How to create a Custom Dialog box in android?

帅比萌擦擦* 提交于 2019-11-25 22:55:50
问题 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 result was not as expected. Then I tried using a plain Dialog class. The result was not as expected. In all three cases, the problem is when I overlook the title view

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

断了今生、忘了曾经 提交于 2019-11-25 22:48:28
问题 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

How do I display an alert dialog on Android?

与世无争的帅哥 提交于 2019-11-25 22:37:01
问题 I want to display a dialog/popup window with a message to the user that shows \"Are you sure you want to delete this entry?\" with one button that says \'Delete\'. When Delete is touched, it should delete that entry, otherwise nothing. I have written a click listener for those buttons, but how do I invoke a dialog or popup and its functionality? 回答1: You could use an AlertDialog for this and construct one using its Builder class. The example below uses the default constructor that only takes

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

与世无争的帅哥 提交于 2019-11-25 21:55:45
问题 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 I click on the \"no\" button. How can I disable this? By the way, I have used PositiveButton and NegativeButton for the button on dialog. 回答1: EDIT: This only works on API 8+ as noted by some of the