Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android dialoginterface get inner dialog views

Tags:

android

dialog

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?

like image 547
user1220817 Avatar asked Mar 19 '12 13:03

user1220817


People also ask

How do I get view from AlertDialog?

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.

What's a dialog in Android?

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.

What is dialog explain Alert dialog with example?

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.


1 Answers

You can retrieve the views from the Dialog in the onClick() with:

EditText edit = (EditText) ((AlertDialog) dialog).findViewById(R.id.the_id_of_view); 
like image 107
user Avatar answered Oct 13 '22 16:10

user