0

I can't figure out how to make the numbers from the string that the tesseract.getUTF8Text() method return. Example input:

foo bar 2.00 foo foo

bar bar foo 6.34

I need to set the text in a TextView where the numbers 2.00 and 6.34 can be clicked and will call a function, but the other text stays the same.

Any help is appreciated

Community
  • 1
  • 1

1 Answers1

1

android.text.style.ClickableSpan can solve you problem.

SpannableString ss = new SpannableString("foo bar 2.00 foo foo");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
    startActivity(new Intent(MyActivity.this, NextActivity.class));
}
@Override
public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }
};
ss.setSpan(clickableSpan, i, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // where i and j should be the start and end index of your clickable string.
textView.setText(ss);
Gopal
  • 1,734
  • 1
  • 14
  • 34