0

I have the fallowing text: "By clicking OK you will disable the service. Learn more".

i want to make "Learn more" clickable, however i want a popup menu to appear instead of directing to a website

i have used the fallowing stack question : How to set the part of the text view is clickable

which worked great. i found the index of learn more by ". ". this solution crashes the application in Chinese and Hindi languages (in Hindi a point is written -> |).

How can i make the "Learn more" clickable in a generic way to show a popup menu?

Is there maybe a way to define the click action in strings.xml, like calling a link? (instead of calling a link -> launch popup menu?)

Community
  • 1
  • 1
BennyP
  • 1,737
  • 1
  • 18
  • 24

3 Answers3

0

You can use WebView and anchor. Create new WebViewClient (especially you need this method: shouldOverrideUrlLoading()) and do everything you want when user will click your anchor.

Artur Szymański
  • 1,639
  • 1
  • 19
  • 22
0

You can create a click event based on the text as you defined.. Check this library.. it may help you.. https://github.com/klinker24/Android-TextView-LinkBuilder

Brendon
  • 1,368
  • 1
  • 12
  • 28
0

solved it, might be a hack but it works fine.

in strings.xml i have added

//<a></a> tags to be removed later on
<string name="learn_more">By clicking OK you will disable the service. &#60;a&#62;Learn more&#60;&#47;a&#62;</string>

in the code :

TextView textView= (TextView) findViewById(R.id.textViewInLayout);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(R.string.learn_more);

//indexes of the clickable text
int start = textView.getText().toString().indexOf("<a>");
int end = textView.getText().toString().indexOf("</a>");

//set the text as html to make the tags disappear 
textView.setText(Html.fromHtml(getString(R.string.learn_more)));

//make the text clickable
Spannable spannable = (Spannable) textView.getText();

ClickableSpan myClickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
       yourActionHere();
  }
};

// end - 3 beacuse of </a>
spannable.setSpan(myClickableSpan, start, end - 3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);`
BennyP
  • 1,737
  • 1
  • 18
  • 24