Well, actually you can embed a callback link to a TextView.
You just need special clickable span, which will call your methods
when clicked.

Here's an excerpt from my HTMLDialog class:

public void setHTML(String html) {
        html=html.replaceAll("(\r\n|\n)","");
        Spanned spannedHTML=Html.fromHtml(html);
        SpannableString message=new SpannableString(spannedHTML.toString());
        Object[] spans=spannedHTML.getSpans(0,spannedHTML.length
(),Object.class);
        for (Object span: spans) {
                int start=spannedHTML.getSpanStart(span);
                int end=spannedHTML.getSpanEnd(span);
                int flags=spannedHTML.getSpanFlags(span);
                if (span instanceof URLSpan) {
                        URLSpan urlSpan=(URLSpan)span;
                        if (urlSpan.getURL().startsWith(CallbackSpan.PREFIX)) {
                                span=new CallbackSpan(urlSpan.getURL());
                        }
                }
                message.setSpan(span,start,end,flags);
        }
        m_message.setText(message);
}

....

protected void onCallback(String data) {
        ....
}

private final class CallbackSpan extends ClickableSpan {
        public CallbackSpan(String url) {
                int start=(url.startsWith(PREFIX)?PREFIX.length():0);
                m_data=url.substring(start);
        }
        public void onClick(View view) {
                onCallback(m_data);
        }
        public static final String PREFIX="callback:";
        private String m_data;
}

and then you can put links of form <a href='callback:mydata'>callback
link</a> anywhere in your document.

Don't forget to setup your TextView:
m_message.setLinksClickable(true);
m_message.setMovementMethod(LinkMovementMethod.getInstance());


Dmitry

On 4 сен, 01:04, Ken H <hunt1...@gmail.com> wrote:
> Is it possible to use a hyperlink in android to do something other
> than open a web page? I want to use a hyperlink in a TextView to
> luanch a new activity, or something along those lines. I have a large
> document and I want to let the user jump to references within the doc
> (like a footnote or something). Can this be done?
>
> Ken
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to