2

I have:

String desc="Drugs in this section include antimuscarinic compounds (section 4.3) and drugs believed to be direct relaxants of intestinal smooth muscle. The smooth muscle relaxant properties of antimuscarinic(section 4.4) and other antispasmodic drugs may be useful in irritable bowel syndrome(section 4.5) and in diverticular disease.The dopamine-receptor antagonists metoclopramide and domperidone (section 4.6) stimulate transit in the gut.";

I want to make (section 4.3), (section 4.4), (section 4.5), (section 4.6) clickable with different click targets.

How can I implement it?

Armfoot
  • 4,417
  • 3
  • 42
  • 59

2 Answers2

1

Use html to achieve the linking: Android: textview hyperlink

Use scheme intent filters to handle the link clicks: How to implement my very own URI scheme on Android

Community
  • 1
  • 1
Machinarius
  • 3,467
  • 1
  • 27
  • 50
1

You can use ClickableSpan finding parenthesis like this:

TextView myTextView = new TextView(this);
String myString = "Drugs in this section include antimuscarinic compounds (section 4.3)";
int i1 = myString.indexOf("(");
int i2 = myString.indexOf(")");
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
myTextView.setText(myString, BufferType.SPANNABLE);
Spannable mySpannable = (Spannable)myTextView.getText();
ClickableSpan myClickableSpan = new ClickableSpan()
{
 @Override
 public void onClick(View widget) { /* do something */ }
};
mySpannable.setSpan(myClickableSpan, i1, i2 + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
jlopez
  • 6,287
  • 2
  • 51
  • 90