0

i am opening a website using linkify feature of android and getting %20 in my url when opening from my device so what should i do?

here is what i am doing

license=(TextView)findViewById(R.id.find_us_tv3);

    license.setTextSize(18);
    Pattern pattern=Pattern.compile("p"+"[page stackoverflow]+stackoverflow");

    license.setText(" Open the demo page stackoverflow.");
    license.setLinksClickable(true);
    Linkify.addLinks(license, pattern, "http://stackoverflow.com/questions/ask"); 
dev_android
  • 493
  • 1
  • 11
  • 29

2 Answers2

2

The "http:/" in your code of
"Linkify.addLinks(license, pattern, "http:/https://stackoverflow.com/questions/ask")"
twice doesn't help.

Just use:

Pattern pattern = Pattern.compile("www.stackoverflow.com/questions/ask");
Linkify.addLinks(license, pattern, "http://");  

Where the text that you mention in pattern should be a part of the text you set in your TextView

Refer: linkify blog link

Community
  • 1
  • 1
Pararth
  • 8,114
  • 4
  • 34
  • 51
  • actually i have text about 5 lines and i am adding pattern for that given word like license. and want to open a specific web page onclick. – dev_android Apr 29 '14 at 05:38
  • you can just specify the word in pattern, that should work...for your textview – Pararth Apr 29 '14 at 05:39
  • is it opening the page or not? – Pararth Apr 29 '14 at 05:47
  • no my link is same as Linkify.addLinks(license, pattern, "http://stackoverflow.com/questions/ask") and adding %20 from device.(http hidden in comment) – dev_android Apr 29 '14 at 05:50
  • pls change your pattern.compile and evaluate the string value. Also have a look at [this](http://stackoverflow.com/questions/4746293/android-linkify-textview), where is it adding the %20 ? – Pararth Apr 29 '14 at 06:06
  • no its not working @user2450263... and please why everybody is voting down :( – dev_android Apr 30 '14 at 05:48
1

Try this:

TextView tvWeblink = ((TextView) findViewById(R.id.textView));
        tvWeblink.setTypeface(LandingScreen.font);

        tvWeblink.setClickable(true);
        tvWeblink.setMovementMethod(LinkMovementMethod.getInstance());
        String text = "By pressing this It will open stack overflow page <a href=\"http://stackoverflow.com/questions/ask/\"> ask a question. </a>.";
        tvWeblink.setText(Html.fromHtml(text));
Manish Dubey
  • 4,206
  • 8
  • 36
  • 65