Note that there are some explanatory texts on larger screens.

plurals
  1. POClickable Hyperlinks in DialogFragment
    text
    copied!<p>This is my static inner class for creating an AlertDialog inside my MainActivity class:</p> <pre><code>public static class AboutDialogFragment extends DialogFragment { public static AboutDialogFragment newInstance() { AboutDialogFragment frag = new AboutDialogFragment(); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setIcon(R.drawable.ic_dialog_about) .setTitle(R.string.about) .setMessage(R.string.about_message) .......... .create(); } } </code></pre> <p>And I'm showing it when you press a menu item which is inside MainActivity:</p> <pre><code>case R.id.about: DialogFragment aboutFragment = AboutDialogFragment.newInstance(); aboutFragment.show(getSupportFragmentManager(), "about_dialog"); // Make links clickable ((TextView) aboutFragment.getDialog().findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); return true; </code></pre> <p>I'm trying to make the links in the message text clickable using the commented line.</p> <p>I found this method <a href="https://stackoverflow.com/questions/1997328/android-clickable-hyperlinks-in-alertdialog">here</a> and it has worked for me when using a regular Dialog (no fragments).<br /> However, this is the first time I have tried using it on a DialogFragment and I always get a NullPointerException when trying to find the view.</p> <p>I've also tried <code>aboutFragment.getView().findViewById(android.R.id.message)</code> but that returns null as well.</p> <p>Maybe I am calling the code too early/in the wrong place?<br /> Any ideas would be great!</p> <p>EDIT: Just tried <code>((TextView) v.getRootView().findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());</code> and <code>((TextView) v.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());</code> in onCreateView() and also tried in onCreateDialog() without success.<br /> Still getting null pointer exception...</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