Reputation: 118
I want to add multiple click able links in text view! get get response of each clicked text.
Upvotes: 4
Views: 925
Reputation: 600
This might help,which explains creating tags like in Rss Feed Apps
private void makeTagLinks(final String text, final TextView tv) {
if (text == null || tv == null) {
return;
}
final SpannableString ss = new SpannableString(text);
final List items = Arrays.asList(text.split("\\s*,\\s"))
int start = 0, end;
for (final String item : items) {
end = start + item.length();
if (start < end) {
ss.setSpan(new MyClickableSpan(item), start, end, 0);
}
start += item.length() + 2;//comma and space in the original text ;)
}
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(ss, TextView.BufferType.SPANNABLE);
}
Upvotes: 1
Reputation: 2211
TextView textView= (TextView)view.findViewById(R.id.textViewAboutUs);
SpannableString ss = new SpannableString("Your String");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
//Do whatever
}
};
ss.setSpan(clickableSpan, starting_position, end_position, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //spanned string, for multiple string define multiple ss.setSpan
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
Upvotes: 0