Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling DialogFragment
    primarykey
    data
    text
    <p>I have set up my Dialog Fragment class successfully, and now I would like to call it from my main Fragment class I have set up.</p> <p>I have tried using multiple code to call it, but I keep getting errors and crashes.</p> <p>What would I need to put in my onClick to call my Dialog Fragment? </p> <p>Thanks in advance!</p> <p>Main Fragment Class:</p> <pre><code> @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_detail_fragment, container, false); mImageView = (RecyclingImageView) v.findViewById(R.id.imageView); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { //Here } }); return v; } </code></pre> <p>Dialog Fragment:</p> <pre><code>class MyDialogFragment extends DialogFragment { Context mContext; public MyDialogFragment() { mContext = getActivity(); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( mContext); alertDialogBuilder.setTitle("Set Wallpaper?"); alertDialogBuilder.setMessage("Are you sure?"); // null should be your on click listener alertDialogBuilder.setPositiveButton("OK", null); alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); return alertDialogBuilder.create(); } public static MyDialogFragment newInstance() { MyDialogFragment f = new MyDialogFragment(); return f; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload