0

I have a ScrollView containing a TextView. I linkify parts of that TextView with

    Pattern pattern = Pattern.compile("MyLink");
    Linkify.addLinks(textView1, pattern, "mylink://");

I habe an Intent filter in my Manifest for mylink:// so a new Activity is opened when MyLink is clicked (as described in this question). This works most of the time, sometimes though a click on the MyLink portion of the TextView doesn't open the Activity but only scrolls the ScrollView in which my TextView resides to the top.

Where does this behaviour come from and how can I fix it?

Community
  • 1
  • 1
fweigl
  • 21,278
  • 20
  • 114
  • 205

2 Answers2

0

If you are attempting to open a link that leads to your current activity, it might be recreating the same activity and gives the sensation that it's scrolling up. Probably you want to modify your manifest and set the activity's launchMode attribute to singleTask

Jorge Mendez
  • 674
  • 4
  • 15
  • Good idea, but that is not the case and the activity thats supposed to open also is not open already in the stack. – fweigl Feb 17 '15 at 17:58
  • Do you know if the target activity is actually being created? Or the layout just scrolls to the top and doesn't open the target activity? I'm thinking that the target activity is actually being created and destroyed immediately and when the current activity is resumed it's scrolled back to the top – Jorge Mendez Feb 17 '15 at 18:07
0

Why dont you use TextViewWithLinks?

With that you can have two types of click on the textview,

1. On TextView

2. On Link TextView

String text = "bananas on www.bananas.ba and  <a href=\"http://google.com/\">Google</a>";

    TextViewWithLinks textview = new TextViewWithLinks(this);
    textview.setText(Html.fromHtml(text));
    textview.linkify(new TextViewWithLinks.OnClickLinksListener() {
        @Override
        public void onTextViewClick() {
            // Do whatever you want
        }

        @Override
        public void onLinkClick(String url) {
            // Do whatever you want
        }
    });

    //SET Colors
    textview.setLinkColors(Color.RED, Color.BLACK);

    setContentView(textview);

Let me know if this is not resolving your issue.

Enjoy Coding... :)

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188