Answer the question
In order to leave comments, you need to log in
Passing and receiving data from DialogFragment?
Is it possible to pass and receive data from DialogFragment?
public class CustomDialogFragment extends DialogFragment implements
DialogInterface.OnClickListener {
private View form=null;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
form= getActivity().getLayoutInflater()
.inflate(R.layout.dialog, null);
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
return(builder
.setTitle("Сюда передать Title")
.setView(form)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null).create());
}
@Override
public void onClick(DialogInterface dialog, int which) {
// Отсюда забрать данные с диалога и передать в Activity, вызвавшую диалог
}
@Override
public void onDismiss(DialogInterface unused) {
super.onDismiss(unused);
}
@Override
public void onCancel(DialogInterface unused) {
super.onCancel(unused);
}
}
Answer the question
In order to leave comments, you need to log in
everything is simple
in the dialog to pass data
CustomDialogFragment fragment = new CustomDialogFragment ();
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question