android - dismiss spinner when user touches somewhere else - android

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.

Related

Prevent Dialog Box from being dismissed

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

Handling textview hit bottom in alert dialog

I'm setting a message in a simple alert dialog. I need to know if the user has read all the text inside the dialog or not. Is there any way to set a scroll listener or something in an alert dialog?
Create your custom dialog and then set some listener to your custom View. Here's a good example: http://www.mkyong.com/android/android-custom-dialog-example/
and
https://stackoverflow.com/a/10713501

Is it possible to change the behaviour of a dialog button after the dialog has been created?

I am preparing a login dialog that can change to a register dialog.
It has a custom view and contains a clickable text view that I use to switch between the register display and login display.
When a user clicks it I change the title of the dialog and I display or vanish the input box for retyping the password.
However, I can't change the text or the OnClick function of the positive button.
the setPositiveButton method only exists for DialogBuilder but not for the dialog itself.
Do I have to rebuild the entire dialog or is there a way to change the button "on the fly"?
After you have created your dialog, you can access the buttons with help of this:
dialog.getButton(AlertDialog.BUTTON1) //BUTTON1 is positive button
With this you can modify the text of the button.

android: popup menu, popup dialog box

I would like to ask how to set a layout such that when a user presses a button in a row, a popup menu appears next to the button, letting the user choose to edit or delete that row?
also, i would like to ask how can i make a layout such that when the user presses the add button, a popup dialog similar to the AlertDialog pops-up? Inside the pop-up dialog the users can input 4 edittexts?
Can the AlertDialog be amended to accept user input, i.e. EditTexts?
Is there any code for reference?
One easy way to have an edit/delete button is to already have the button in your layout but set its visibility to View.INVISIBLE invisible. When the other button is pressed, just change the edit/delete button's visibility to View.VISIBLE.
For the custom dialog, use AlertDialog.Builder and use the setView() to use your custom layout inside the dialog.
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setView(android.view.View)
Here's a blog post with some sample code:
http://android-coding.blogspot.com/2011/05/create-custom-dialog-using.html

Keep AlertDialog's DialogInterface opened

I have a custom AlertDialog where a user has to set password. There are two edittext views.
I compare them first if they match and if they are more than 3 characters long. If they don't match, I display a toast to alert the user. But after submitting and checking the dialog closes. How can I keep it opened until user inserts the correct values?
I was looking at doing something similar and I could not find a way do this with the standard AlertDialog as it is.
One possible way I found was to not specify any button listeners in your AlertDialog and instead place a view with your own custom buttons that perform the checks and then dismiss the dialog if necessary. I've not yet tried this to see how it works.
Another option is to create your own Custom dialog by subclassing Dialog.
You have to set a global variable like
boolean showAlert = true;
And attach a onClick listener to the AlertDialog and after cheking to see if there is need to show the alert again. If there is a need, you should show it again. You can`t keep it open if the user clicks a button from the AlertDialog. You have to recreate it again.

Categories

Resources