1

What I'm trying to accomplish: create a clickabel hyperlink in the message text displayed by a DialogPreference.

My solution so far: follow this topic: link , and I am accomplished a formating hyperlink displayed in the DialogPreference, but this hyperlink not clickable.

Question:How to make the hyperlink clickable in the DialogPreference.

my code:

public class AboutDialog extends DialogPreference {
public AboutDialog(Context oContext, AttributeSet attrs)
{
    super(oContext, attrs);
    final SpannableString s = new SpannableString(oContext.getText(R.string.about_text));
    Linkify.addLinks(s, Linkify.ALL);
    this.setDialogMessage(s);
}}
Community
  • 1
  • 1
pixeloverflow
  • 579
  • 1
  • 5
  • 23

2 Answers2

2

Well, I am not sure but try this :

  • Create textView, set your string s as it's text, using yourTextVeiw.setText(s)
  • set onClickListener for this textView
  • Now set this textView into dialog, try using addView(textview) , method.
user229044
  • 232,980
  • 40
  • 330
  • 338
viv
  • 6,158
  • 6
  • 39
  • 54
  • viv, thanks very much for your reply. But it doesn't work. the DialogPreference just has onBindView(View). I tried various methods in your way, but it doesn't work. now I try to use other API take over the DialogPreference:) – pixeloverflow Nov 28 '10 at 16:33
  • You are a nice guy. I wanna accomplish a "About" Dialog in the PreferenceScreen and add a clickable hyperlink in the "About" Dialog, so I stuck in there:) – pixeloverflow Nov 28 '10 at 16:58
  • well ycz, it's getting a bit tricky for me atleat, there is a onCreateDialogView(), method which returns View, so if it can be overrided, but just clarify me one thing, do you want to show hyperlink in some dialog type of view or only in DialogPreference, is it(DialogPreference) that much mandatory, i mean why not use a simple dialog .... – viv Nov 28 '10 at 17:03
  • -_-! Because My App already has 4 icons in the main menu, I am very lazy, I won't to draw a new icons for the "About dialog". and I did a lot of search for "how to create a dialog in the Preferencescreen", but I just found using DialogPreference. well it seems I will do some art work :) – pixeloverflow Nov 28 '10 at 17:20
  • ha ha, well i am getting helpless with DialogPreference at present, in case in future if you don't get any workaround with DialogPrefernce, you can do it with simple dialog, i will also be able to help in that case, as i have used them frequently, just leave a comment in future here and i will be notified, hope you get what you want to achieve, god bless you .... – viv Nov 28 '10 at 17:25
  • thanks again, god bless you :) finally I add a item in menu for about dialog and save the unclickable link about dialog" in the preference:) – pixeloverflow Nov 28 '10 at 18:04
0

This seems to work

package net.anei.cadpage.preferences;

import android.content.Context;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

public class DialogPreference extends android.preference.DialogPreference {
  public DialogPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public DialogPreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
  protected View onCreateDialogView() {
    final SpannableString s = new SpannableString(getDialogMessage());
    Linkify.addLinks(s, Linkify.WEB_URLS);
    final TextView view = new TextView(getContext());
    view.setText(s);
    view.setMovementMethod(LinkMovementMethod.getInstance());
    return view;
  }
}
kencorbin
  • 1,958
  • 1
  • 20
  • 18