I've a simple program to show a dialog, with a edittext view in it, and listen to positive/negative buttons, to perform a custom action in each (read that edittext and save its content to an activity variable).
The problem arises when I can't see any way to recover my current dialog from dialog interface (and then, I can't recover any view within dialog).
Probably it's a noob question, but after some google searches, I've no one answer to it.
My code is the following
LayoutInflater li = LayoutInflater.from(this); View myView = li.inflate(R.layout.my_layout, null); AlertDialog.Builder cDialog = new AlertDialog.Builder(this); cDialog.setView(myView); cDialog.setPositiveButton(R.string.start_download, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //here the code to retrieve dialog } }); cDialog.create();
Any clue about where can I find that?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
You can retrieve the views from the Dialog
in the onClick()
with:
EditText edit = (EditText) ((AlertDialog) dialog).findViewById(R.id.the_id_of_view);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With