1

Essentially I want to make something like http://stackoverflow.com appear as "Stack" in a checkedtextview and be a link. How can I do that?

mergesort
  • 5,087
  • 13
  • 38
  • 63

1 Answers1

1

TextView can display dumbed-down tagsoup HTML, including <a href=""/> tags. If that's in strings.xml, and you set the text using android:text, it should just happen automatically. Otherwise, you'll need to pass the html string to Html.fromHtml(). Example:

CheckedTextView ctv = (CheckedTextView) findViewById(R.id.whatever);
ctv.setText(Html.fromHtml("<a href=\"http://stackoverflow.com\">Stack</a>"));

Your layout should also set android:linksClickable="true" on the CheckedTextView

Joe
  • 42,036
  • 13
  • 45
  • 61
  • I tried this and it almost works. It just won't let me click the link, even by changing the property in the layout – mergesort Jun 21 '11 at 20:27
  • 1
    The most likely reason for that is `CheckedTextView` is not usually clickable (see [my answer here](http://stackoverflow.com/questions/2627222/android-checkedtextview-cannot-be-checked/2806669#2806669)) because it's intended as a simplified single-view `ListView` item where the `ListView` handles the checked state via `choiceMode`. You get what what you want with `android:clickable="true"` as well, but if it's in a `ListView`, that could cause problems (such as the click event not triggering the ListView). Also try [CheckBox](http://developer.android.com/reference/android/widget/CheckBox.html) – Joe Jun 25 '11 at 05:00