2

So I have a TextView with some text as follows

some text....some text....some text....some text....some text....some text....some text....some text......href.link......some other text.....some other text......some other text.....some other text....some other text...

I just want the link part of the text to start another activity when clicked. I am trying to do this in Xamarin, so far I have done the following:

TextView1.SetText(Html.FromHtml("<span>some text...<a href='example://'></a>...some other text </span>"

In my target activity:

[IntentFilter(new[] { Intent.ActionView },
     DataScheme = "example",
Categories = new[] { Intent.CategoryDefault })]

which I am guessing is equivlent to:

<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="example" />  
</intent-filter>

Not sure what to set as the scheme here.

benin101
  • 131
  • 3
  • 13

2 Answers2

2

I figured it out. Apparently I have to add this to the code (in question) to make it work -

TextView1.MovementMethod = LinkMovementMethod.Instance;
benin101
  • 131
  • 3
  • 13
0

This is how I am doing a similar thing in Xamarin. I have a TextView called lblCreateNewAccount in my Layout. In the OnCreate method of the activity, I am doing this:

TextView lbl = this.FindViewById<TextView> (Resource.Id.lblCreateNewAccount);
lbl.TextFormatted = Android.Text.Html.FromHtml ("<u>Create New Account</u>");
lbl.SetTextColor (Color.ParseColor ("#ffffff"));
Typeface face = Typeface.CreateFromAsset (this.Assets, "fonts/OpenSansRegular.ttf");
lbl.SetTypeface (face, TypefaceStyle.Normal);
lbl.Click += lblCreateNewAccount_Clicked;

Here is the simplified lblCreateNewAccount_Clicked method for you:

void lblCreateNewAccount_Clicked (object sender, EventArgs e)
{
    this.StartActivity (typeof(NewAccountActivity));
}

Basically the concept is to format the TextView as an href and then implement the Click event to navigate to the next activity. Not sure if this is the best and most elegant way but it works for me.

By the way, you will have to use three TextView controls in this case.

Ahmed Salman Tahir
  • 1,783
  • 1
  • 17
  • 26
  • Thanks. Actually the whole text is too long to keep them in one line. So keeping three TextViews is not gonna help. Its like the link comes up somewhere in the middle of a paragraph – benin101 Sep 12 '14 at 15:51