Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I would do that (untested code) ;)</p> <p>Your custom Dialog:</p> <pre><code>public class AdDialogFragment extends DialogFragment { String mProduct; String mDescription; String mCompany; TextView mProductTV; TextView mDescriptionTV; TextView mCompanyTV; public void setAdInfo(String product, String desc, String company) { mProduct = product; mDescription = desc; mCompany = company; } public AdDialogFragment() { super(); } public static AdDialogFragment newInstance() { return new AdDialogFragment(); } public Dialog onCreateDialog(final Bundle savedInstanceState) { LayoutInflater factory = LayoutInflater.from(getActivity()); final View content = factory.inflate(R.layout.ad_dialog, null); mProductTV = (TextView) content.findViewById(R.id.product); mDescriptionTV = (TextView) content.findViewById(R.id.description); mCompanyTV = (TextView) content.findViewById(R.id.company); fillTextViews(); AlertDialog.Builder dialog; if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) { dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.Theme.DeviceDefault.Dialog.)); //can't remember the name or create a custom theme. } else { dialog = new AlertDialog.Builder(getActivity());//anything below honeycomb can die :). } // now customize your dialog dialog.setTitle(getActivity().getString(R.string.some_title_if_any)) .setView(content) .setCancelable(true) //this is the default I think. .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // do something } }); .setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return dialog.create(); } private void fillTextViews() { mProductTV.setText(mProduct); mDescriptionTV.setText(mDescription); mCompanyTV.setText(mCompany); } </code></pre> <p>And this is how you call it from an Activity for example: </p> <pre><code>public void showYourFancyDialog() { AdDialogFragment dialog = AdDialogFragment.newInstance(); dialog.setAdInfo(yourProduct, yourDescription, yourCompany); dialog.show(getSupportFragmentManager(), "dialog"); } </code></pre> <p><sub>Using patterns from <a href="http://developer.android.com/reference/android/app/DialogFragment.html" rel="nofollow">Google's documentation</a></sub></p>
 

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