I have a user dialog derived from DialogFragment.
When the user clicks OK, I need to save the information that is on the screen.
So, I turned off my PositiveButton calls, and I implemented the onDismiss method to save the data.
In the onDismiss method, I need to get the data from the editView, which is in the dialog box. I am using getView (). FindViewByID to get editView, but the GetView () method returns null.
Here is my code:
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); builder.setView(inflater.inflate(R.layout.dialog_signin, null)) .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { LoginDialogFragment.this.getDialog().dismiss(); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { LoginDialogFragment.this.getDialog().cancel(); } }); return builder.create(); } @override public void onDismiss(){ EditView view = (EditView)getView().findViewByID(R.id.edit); }
I know that I can save a view inflated in OnCreateDialog as an attribute, but it seems wrong to me.
How can I get a view from the screen in onDismiss?
Ps: the place where I work does not allow me to send my code, so I took the code from Google and I changed it as close as possible to my code.
source share