-1

I have 5 text views which contain 1-5 words each . I need to set onclicklistener for individual texts of textview . The textview should also highlight / indicate the text which is clicked . How can i achieve this efficiently ?

I have a listview of maximum 5 textview . Each textview contain one or more words . I need to open different url depending upon the word that is clicked. The Problem is text view is set at runtime i.e variable length . Can i still achieve this using Clickable span and Spannable string .

randy
  • 765
  • 7
  • 24
  • 4
    look into this http://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable – Tomer Shemesh Jun 06 '16 at 21:05
  • 1
    As Tomer said you should follow ClickableSpan. Via this way you can add spans any part of the text and remove when needed – ugur Jun 06 '16 at 21:37

1 Answers1

0

You can set clickable true for particulal textView in your xml file. Then just use setOnClickListener method. And inside of this method set text color.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true" />

and inside the java class:

textView.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
     textView.setTextColor(int yourColor); //e.g. Color.BLACK
  }
});
dhian
  • 3
  • 2