title: clickable span in a ListView
body: <p>I'm trying to implement a comment like list where you can mention other users in the comments, and then be able to click on that to go to their profile. For example, when posting a comment on reddit you can mention another user with /u/username. </p>
  
  <p>The one problem i'm running into is how to make it so I can click on the text to load that user's profile. </p>
  
  <p>For the comment list I essentially have a custom list of textviews. From googling around I saw that it is possible to be able to click on some text in a textview using a clickable span. However, I haven't been able to get this to work in a list of textviews. Can someone help?</p>
  
  <p>This is the relevant sections of my code:</p>
  
  <p>Clickable span I declared as a member variable:</p>
  
  <pre><code>ClickableSpan clickableSpan = new ClickableSpan() {
  
      @Override
      public void onClick(View widget) {
          Intent intent = new Intent(context, ProfileActivity.class);
          // ParseUser.getQuery().whereEqualTo(Constants.kQollegeUserPreferredUsernameKey, sta)
          intent.putExtra("User", ParseUser.getCurrentUser().getObjectId());
          context.startActivity(intent);
      }
  };
  </code></pre>
  
  <p>Inside getView:</p>
  
  <pre><code>    TextView answer_text_view = answerView.getAnswerTextView();
  
      String text = answer.getAnswerText();
      if(text.contains("@")) {
          text += " ";
          final SpannableStringBuilder sb = new SpannableStringBuilder(text);
  
          List&lt;Integer&gt; start = new ArrayList&lt;&gt;();
          int index = text.indexOf("@");
          while (index &gt;= 0) {
              start.add(index);
              index = text.indexOf("@", index + 1);
          }
  
          for(int i = 0; i&lt;start.size(); i++){
              sb.setSpan(fcs, start.get(i), text.indexOf(" ", start.get(i)), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
              sb.setSpan(clickableSpan, start.get(i), text.indexOf(" ", start.get(i)), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
          }
  
          answer_text_view.setText(sb);
      }
  </code></pre>