I have a dialogfragment, which should dismiss, if i click outside of the dialog. I have no button or something else to close the dialog.
But before the dismiss is calling, I want to check a field in my dialog. If the check is positive, then the dialog should close, else not.
Which method can I override to do that? Or can I do it manual with a onTouchListener, which dismiss the dialog, if I'm clicking beside?
I would do following. I would add transparent button on background of your dialog fragment in order to fragment take all place and set onClickListener for that button. Maybe it's wierd but it's work ))
Related
There is a Dialog Box, how can I prevent it from being dismissed? I want not only the user enter a username but also prevent him/her from leaving the box empty?
dialog.setCancelable(false);
This function call will make your dialog dismissable by touch on the outside of the dialog. Moreover, you can control the actions of the positive and negative buttons. However if you have custom dialog with edit text in it then you should check the string that you get from edittext when user click the positive or negative button and not call dialog.dismiss(); method if string is empty. Hope it helps.
Try this code, it prevents user from dismissing the dialogue box
myDialog.setCancelable(false);
The application displays a custom dialog by using the code dialog.show(getActivity().getSupportFragmentManager(), TAG); with in a conditional statement from OnStart method of a fragment.
But the issue is, after dismissing the fragment and navigate to any other Activity and click on back button displays the custom dialog again even the conditional statement is false.
How to suppress the dialog from being displayed.
In your onStop and onPause dismiss the dialog by dialog.dismiss(). Make a global object of dialog.
The reason is that you dialog is never dismissed and it stays in your activity so when you come back it is shown.
Do you set your condition to false after dialog dismiss?
I made a custom dialog (extends Dialog) and then make the object in Activity Sample.class
Then if I click one button in the Activity and the custom dialog shows up.
Here, the problem is, since the custom dialog contains the EditText, the soft keyboard is needed and it shows up, but if I click(tab) the screen outside of the dialog, the "cancel" listener is called so that the dialog is disappeared. However, what I want to implement is when I click the screen outside of the dialog, only just keyboard disappearing. Can anyone help me?
Use setCanceledOnTouchOutside(false) on the dialog instance. This will stop dismissing the dialog. But I am not sure the soft keypad will go away with this.
use this,
dialog.setCanceledOnTouchOutside(false);
I have an app where the user presses a button and a custom spinner is popped so that the user can choose between nine colors. I want the spinner to be dismissed, when the user touches the background (every place on the sreen except from the spinner). Is this possible?
I tried to add an onTouchListener on the image that covers the background and call
dialog.dismiss();
but it does not work.
My spinner is custom Spinner, set in an xml file and popped with:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.colorchooser);
Thank you in advance
First of all you should be able to add
dialog.setCanceledOnTouchOutside(true);
to accomplish what you want.
But the dismiss() method should also be working, I would guess that the place your are calling dialog.dismiss() is not reachable at the current moment.
I have a dialog with five CheckedTextView. When I open dialog and Click on some CheckBoxes and than I click Cancel Button. But when I open dialog again. The changes made is saved. Why? How to cancel what I clicked when I press Cancel button ?
Android creates the dialog box just once, and then reuses it instead of recreating it. Thus, your onCreateDialog method is called only once. The second time, you get the same dialog, with the same check boxes in the same state.
To ensure that the dialog contains the correct data, override onPrepareDialog. This gets called every time right before the dialog is shown. From here, you can set the check boxes to the desired state.