On a button click say status, i want that a pop up window appears which lets a user set a status message and which in turn is displayed in the status message field.
I thought of using a customized alert dialog.
here is the xml file of my dialog layout:
I am getting the dialog. However onpositiveButtonClick
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<EditText android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
in the java file, i am displaying the dialog as follws:
Code:
AlertDialog.Builder builder;
Context mContext = MyProfileActivity.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.status_dialog,
(ViewGroup) findViewById(R.id.layout_root));
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setTitle("Add Status message").
setCancelable(false).
setPositiveButton("Update Status", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText text = (EditText) layout.findViewById(R.id.text); // compile time error
TextView statusTxt = (TextView)findViewById(R.id.status_txt);
statusTxt.setText(text.getText().toString());
MyProfileActivity.this.dismissDialog(DIALOG_STATUS);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog = builder.create();
Now i am getting the dialog, but i am not able to retrieve the text entered the text field on positive(update) button click..
Please suggest me a way to retrieve my editText view in onclick() method.