Old but gold. This one allows to have bigger control over whole fragment (for example when implementing seekBar or using ButterKnife). Enough said:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_signin, null);
// do your stuff with views here
builder.setView(view)
.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();
}
I know I can save the view inflated in the OnCreateDialog as a attribute, but that doesn't seems right to me.
Yeah, that's the one. It looks right though, especially when implementing things like seekBar and while using libraries like ButterKnife.