tags:

views:

36

answers:

1

I have this currently.

ClickableSpan span = new ClickableSpan(...){...};

String text = "I am some <b>awesome</b> text";
Spanned spanned = Html.fromHtml(text);
SpannableStringBuilder builder = new SpannableStringBuilder(spanned);
int start = builder.nextSpanTransition(0, builder.length(), StyleSpan.class);
int stop = builder.nextSpanTransition(start, builder.length(), StyleSpan.class);
builder.setSpan(span, start, stop, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(builder);

The TextView renders with the text that has the word "awesome" bolded and underlined (Yay). However in my view, I cannot focus the subregion of text I specified in the clickablespan. I can click on it with a touch event, but I cannot focus it. I am testing this on Android 1.5 + 2.1. I have also tried UrlSpan as well.

I have also tried instead of using a ClickableSpan, to actually attach an onClick listener to the entire block of text but that doesn't give the region focus, just makes clicking easier. Please help

+2  A: 

Ok I just figured it out. I originally was looking at the UrlSpan documentation and then just blindly implemented ClickableSpan.

textView.setMovementMethod(LinkMovementMethod.getInstance());

And magically through the powers of this undocumented class ... it works. So basically what I think is going on, is the MovementMethod is a way to supply a textview with a strategy to handle cursor input.

Greg