0

I'm new to android. I was wondering how can make a portion of text act like a HTML link tag but instead of a webpage, it launches an activity.

In my text view i have need to put link to other activities, the problem is my text view can have different text depending on the user request and each text has its own links.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Amson
  • 74
  • 8
  • 4
    http://stackoverflow.com/questions/1697084/handle-textview-link-click-in-my-android-app – calsign Sep 01 '12 at 17:46
  • thanks i have seen that post already, i couldn't understand it at first so thought it's not relevant. But don't you think making more than three activities listening to action.view is bad for performance. – Amson Sep 01 '12 at 18:32

1 Answers1

0

U can use this code for adding click listener to the text view and then you can do whatever you want in the onClick() method.

SpannableString content = new SpannableString("this is spannable string");
        content.setSpan(new ClickableSpan() {

            @Override
            public void onClick (View widget)
            {
                Toast.makeText(Activity.this, "my text", Toast.LENGTH_SHORT).show();
            }
        }, 0, content.length(), 0);

        text.setMovementMethod(LinkMovementMethod.getInstance());
        text.setFocusable(true);
        text.setText(content);
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
karn
  • 5,963
  • 3
  • 22
  • 29