How to setText and getText in alertDialogs
<p>I am using an AlertDialog as a data entry and the layout includes a few EditText fields. I can reference those fields, but seems to not be able to setText or getText:</p>

<p>This is the xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Date (mm/dd/yyyy)"
    android:inputType="date"
    android:id="@+id/et_appointment_add_date" /&gt;

&lt;EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Start Time"
    android:inputType="time"
    android:id="@+id/et_appointment_add_start_time" /&gt;

&lt;EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="End time (optional)"
    android:inputType="time"
    android:id="@+id/et_appointment_add_end_time"/&gt;

&lt;EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Location (optional)"
    android:inputType="text"
    android:id="@+id/et_appointment_add_location" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>and below the code where I try to access them</p>

<pre><code>CalendarView cv = (CalendarView)findViewById(R.id.cv_acitivtyDetails);
cv.setOnDateChangeListener(new OnDateChangeListener() {

@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
        int dayOfMonth) {

        final String dateString = Integer.toString(month) + "/" + Integer.toString(dayOfMonth) + "/" + Integer.toString(year);

        CharSequence options[] = new CharSequence[] {"Show", "Add", "Delete"};

        AlertDialog.Builder builder = new AlertDialog.Builder(ActivityDetails.this);
        builder.setTitle("Appointments");
        builder.setItems(options, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int position) {

            switch (position) {

            case 0:

                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityDetails.this);
                LayoutInflater inflater = ActivityDetails.this.getLayoutInflater();
                builder.setTitle("Add Activity Appointment");
                builder.setMessage(currentAct);
                builder.setView(R.layout.activitydetails_popup_add_activity);
                final View popupView = inflater.inflate(R.layout.activitydetails_popup_add_activity, null);

                // HERE I REFERENCE BOTH EDITTEXTS, THE ONE I WANT TO SET AND THE ONE I WANT TO GET
                final EditText etDate = (EditText)popupView.findViewById(R.id.et_appointment_add_date);
                final EditText etLoc = (EditText)popupView.findViewById(R.id.et_appointment_add_location);

                // HERE I TRY TO SET THE DEFAULT DATE WHEN THE WINDOW POPS UP, BUT IT DOES NOT SEEM TO DO ANYTHING
                etDate.setText(dateString);

                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        // HERE I AM USING A TOAST TO CHECK IF I GET THE TEXT FROM THE EDITTEXT, BUT IT ALWAYS SEEMS TO RETURN AN EMPTY STRING
                        String location = "LOC:" + etLoc.getText().toString();
                        Toast.makeText(getApplicationContext(), location, Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                AlertDialog b = builder.create();
                b.show();


        break;

        case 1:

        break;

        case 2:

        break;

        }

        }
        });
        builder.show();

        }
        });
</code></pre>

<p>I looked at other examples and I can't spot the difference between my implementation and others that seem to work. Is there anything wrong with the order of things I am implementing?</p>