I sought numerous answers/similar questions and non solved my problem. I have a custom dialog implemented in a class that extends "DialogFragment". When I try to get text from any of the layout components I get the initial default text that I sat.
Code snippet :
public class input1_frag extends DialogFragment
{
View v;
LayoutInflater inflater;
EditText email_field,passwd_field;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
inflater = getActivity().getLayoutInflater();
builder.setTitle("Identity verification");
// Inflate and set the layout for the dialog
builder.setView(inflater.inflate(R.layout.input_dialog, null));
builder.setPositiveButton("Modify account", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
v = inflater.inflate(R.layout.input_dialog, null);
email_field = (EditText) v.findViewById(R.id.input_dialog_email0);
passwd_field = (EditText) v.findViewById(R.id.input_dialog_passwd0);
String fetched_email = email_field.getText().toString();
String fetched_passwd = passwd_field.getText().toString();
});}}
input.dialog.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your old data"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow android:id="@+id/tableRow_space_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:layout_width="fill_parent"
android:layout_height="20dp">
</View>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/input_dialog_email0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="E-mail" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/input_dialog_passwd0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="xxx" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TableRow>
</TableLayout>
I made the view & the inflater global to avoid making them final. Yet it still returns the initial text from the textfield.