0

In my android app I have a textview, which i'm using it as a link to open website. But when click on textView a alert pops up the browser isn't responding.

<string name="MoneyControl"><a href="http://www.moneycontrol.com/stocksmarketsindia/"> 1. Money Control</a></string>

<TextView
     android:id="@+id/moneycontrol"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/MoneyControl"
     android:textSize="15dp" />

link = (TextView) findViewById(R.id.moneycontrol);
    if (link !=null){
        link.setMovementMethod(LinkMovementMethod.getInstance());
    }
Android beginner
  • 245
  • 2
  • 6
  • 22
  • Try to set this `android:autoLink="web"` `android:linksClickable="true"` to your `TextView` and Remove `link.setMovementMethod(LinkMovementMethod.getInstance());` – M D Mar 12 '14 at 11:39
  • try this http://stackoverflow.com/a/11259909/1012284 – Padma Kumar Mar 12 '14 at 11:41
  • @Simple Plan doesn't work out for me. – Android beginner Mar 12 '14 at 11:49
  • go to this: [http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable?rq=1](http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable?rq=1) – M D Mar 12 '14 at 11:51

1 Answers1

0

You can use this solution to do that:

SpannableString ss = new SpannableString("Your text here");
ss.setSpan(new StyleSpan(Typeface.NORMAL), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan fcs = new ForegroundColorSpan(Color.BLUE);
ss.setSpan(fcs, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new UnderlineSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

yourTextView.setText(ss);

yourTextView.setOnClickListener(new View.OnClickListener() {
    public void onClick(View arg0) {
        String _url = "Your link here";
        Intent webIntent = new Intent(Intent.ACTION_VIEW);
        webIntent.setData(Uri.parse(_url));
        startActivity(webIntent);
    }

});
Roman Black
  • 3,501
  • 1
  • 22
  • 31