I have a custom DialogFragment and the question is this ... There is an activit which, using the newInstance(int layout) method, gets an instance of the new MyDialog() class in which there are 2 buttons on which the licenser hangs and listens to clicks. Now when you click on the DialogFragment button, DialogFragment just closes ... So I can not guess how I can make it return to the values that caused it before closing (let's say a string string).
Here is the code:
public class MyDialog extends DialogFragment { final String LOG_TAG = "MyDialog"; private static MyDialog myDialog; int layout; @Override public void onCreate(Bundle savedState) { super.onCreate(savedState); Bundle args = this.getArguments(); layout = args.getInt("layout"); } public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()) .setView(layout) .setCancelable(true); if (layout == R.layout.activity_note_dialog) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(layout, null); LinearLayout llSent = (LinearLayout) view.findViewById(R.id.llSent); LinearLayout llSkip = (LinearLayout) view.findViewById(R.id.llSkip); llSent.setOnClickListener(listener); llSkip.setOnClickListener(listener); adb.setView(view); } return adb.create(); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.llSent: System.out.println("FFFFFFFFFFFFFFFFFFFFFFFFFFF"); myDialog.dismiss(); break; case R.id.llSkip: System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDD"); myDialog.dismiss(); break; } } }; public void dismissDialog(final MyDialog dialog, int daleyTime) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { try { dialog.dismiss(); } catch (IllegalStateException e) { e.printStackTrace(); } } }, daleyTime); } public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); Log.d(LOG_TAG, "MyDialog: onDismiss"); } public void onCancel(DialogInterface dialog) { super.onCancel(dialog); Log.d(LOG_TAG, "MyDialog: onCancel"); } public static MyDialog newInstance(int layout) { myDialog = new MyDialog(); Bundle args = new Bundle(); args.putInt("layout", layout); myDialog.setArguments(args); return myDialog; } } Tell me how to do this?