Android Dialog out of dialog click - android

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);

Related

Prevent soft input keyboard from disappearing when display dialog on acitivity

I am trying to show dialog when user touch on edit text. The problem is when I show the dialog, the keyboard is disappear. How to solve this problem? I think this is because when show dialog, the activity loose focus. There is a similar question in SO. When Dialog is showing, outside edittext in activity not showing the soft keyboard in android. But that answer does not work for me. I am using custom dialog which extends android Dialog classs.
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Start Activity from Soft Keyboard WITHOUT hiding the soft keyboard

I know this should not be a big challenge but it really drives me insane.
I am developing a simple soft keyboard input method and basically I have added a button to my softkeyboard, by pressing which, a dialog should pop up to prompt user to do some choices.
By far everything is ok about creating and opening the dialog. Since normally a dialog is created and displayed from outside an activity, so a flick solution could be to create a transparent activity which embedded the dialog in it. By doing so, I could easily start a dialog when user click the button on my softkeyboard.
But one tricky problem is: every time user click the button and the dialog (actually a dialog in a transparent activity) displays, it will always make my softkeyboard hide. I just need to start the dialog without any changes to the status of my softkeyboard -- I want my softkeyboard keeps showing when the dialog starts.
Here is a snapshot of Google Keyboard, it has the similar button which display a dialog and the dialog did not hide the keyboard, this is exactly what I want. So please anyone suggest me how to achieve this. Thanks so much.
THey aren't launching an Activity. They're launching a dialog. Which is tricky from an input method because its a service (you have to specify the dialog's window token to make it show) but doable.

When does touching the screen outside an AlertDialog cancel the AlertDialog?

Suppose you have an AlertDialog with two buttons A and B. I have found that on some devices and some versions of android, if you touch any area of the screen around the dialog, the AlertDialog disappears. On other devices you are forced to select either A or B, so there is no way I can allow the user to cancel the action without adding a third ('Cancel') option to the AlertDialog. Is there any way to determine programmatically whether the third option is required?
You can control it with dialog.setCanceledOnTouchOutside(true);
For more information :
How to dismiss the dialog with click on outside of the dialog?
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);

Cancel Dialogfragment click outside

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 ))

AlertDialog buttons always close the dialog once clicked

I'm using an AlertDialog with 2 buttons (one positive, one negative).
I've set a handler for those buttons which doesn't mention dismiss. Indeed after clicking, I don't want the dialog to close. However, it seems that as soon as we click on a positive/negative button on an AlertDialog, it always get closed.
Is there a way to prevent the dialog from closing after clicking on any button ?
Thanks,
Vincent
Use custom layout for Dialog and you will be happy!
Use a custom dialog, not an AlertDialog.
You can also create a new Activity and assign it the theme dialog in your manifest with
<activity android:name="MyDialogActivity" android:theme="#android:style/Theme.Dialog" />

Categories

Resources