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
Related
I have a Custom Dialog Box that contains an EditText. Now, Whenever I show the Dialog usingDialog.show();, the EditText immediately grabs focus and displays the Soft-Keyboard. I attempted to add this to the manifest:
android:windowSoftInputMode="stateHidden"
Based on this answer: https://stackoverflow.com/a/2611031/3011902
I also tried the following on the EditText:
EditText.setSelected(false);
And:
LinearLayout hidden = (LinearLayout) loginDialog.findViewById(R.id.hidden);
hidden.setVisibility(View.INVISIBLE);
hidden.setFocusable(true);
hidden.requestFocus();
loginDialog.show();
I also tried to manually hide the keyboard right after the dialog is shown, but that feels a bit illegitimate. Is there any easy way to only display the keyboard when the EditText of the Dialog is selected.
You can try redirecting the focus to another view or just invisible view inside your Custom Dialog Box with adding
android:focusable="true" and android:focusableInTouchMode="true"
or
setFocusable(true) and setFocusableInTouchMode(true)
If you have any question about my answer feel free to ask in the comment!
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.
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 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.
I want to show a modal pop up window with a TextView and two buttons when the user "clicks" on a ListView item.
How can I do that?
Take a look at the AlertDialog.Builder class.
http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
The above link should provide you with all the necessary information.