title: SpannableString in XamarinAndroid
body: <p>I've a &quot;text view&quot; with 6 lines.
  I want to show the number of each line with a Toast when I click on each of them.
  When I use &quot;Spans&quot; it just shows the last line number.
  How can write a loop for Spans to return all lines number.
  Any other suggestions?
  Thanks for your help.</p>
  <p>My Code:</p>
  <pre><code>public class Activity1 : AppCompatActivity
  {
      TextView textView;
      int count = 6; //Number of lines
      int next;
      string txt;
  
      protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
          SetContentView(Resource.Layout.activity_main);
  
          textView = FindViewById&lt;TextView&gt;(Resource.Id.textView1);
          txt = Resources.GetString(Resource.String.test);
  
          SpannableString ss = new SpannableString(txt);
          var clickableSpan = new MyClickableSpan();
          clickableSpan.Click += v =&gt; Toast.MakeText(this, &quot;line : 1&quot;, ToastLength.Short).Show();
          ss.SetSpan(clickableSpan, 0, a, SpanTypes.ExclusiveExclusive);
          textView.TextFormatted = ss;
          textView.MovementMethod = new LinkMovementMethod();
  
          //For all lines
              //var clickableSpan1 = new MyClickableSpan();
              //var clickableSpan2 = new MyClickableSpan();
              //var clickableSpan3 = new MyClickableSpan();
              //var clickableSpan4 = new MyClickableSpan();
              //var clickableSpan5 = new MyClickableSpan();
         ...
      }
      private class MyClickableSpan : ClickableSpan
      {
          public Action&lt;View&gt; Click;
  
          public override void OnClick(View widget)
          {
              if (Click != null)
                  Click(widget);
          }
          public override void UpdateDrawState(TextPaint textPaint)
          {
              textPaint.UnderlineText = false;
          }
      }
  }
  </code></pre>
  <p>My Code for loop:
  <a href="https://stackoverflow.com/questions/43270575/how-to-loop-through-the-spans-in-a-spannedstring-or-spannablestring-in-android">From this answer</a></p>
  <pre><code>            for (int i = 0; i &lt; ss.Length(); i = next)
              {
                  // find the next span transition
                  next = ss.NextSpanTransition(i, ss.Length(), Class.FromType(typeof(CharacterStyle)));
                  // get all spans in this range
                  int numOfSpans = 0;
                  //CharacterStyle[] spans = ss.GetSpans(i, next, Class.FromType(typeof(CharacterStyle))); //return null!!!
                  for (int j = 0; j &lt; count; j++)
                  {                        
                        numOfSpans++;
                  }
                  var clickableSpan = new MyClickableSpan();
                  clickableSpan.Click += v =&gt; Toast.MakeText(this, &quot;line : &quot; + numOfSpans, ToastLength.Short).Show(); //return last number of lines : 6
                  ss.SetSpan(clickableSpan, i, next, SpanTypes.ExclusiveExclusive);
                  textView.TextFormatted = ss;
                  textView.MovementMethod = new LinkMovementMethod();
              }
  </code></pre>