【发布时间】:2017-01-24 17:34:01
【问题描述】:
我不知道如何使string 中的数字由tesseract.getUTF8Text() 方法返回。示例输入:
foo bar 2.00 foo foo
bar bar foo 6.34
我需要在TextView 中设置文本,其中可以单击数字 2.00 和 6.34 并调用函数,但其他文本保持不变。
感谢任何帮助
【问题讨论】:
-
您可以对这些号码进行超链接//
我不知道如何使string 中的数字由tesseract.getUTF8Text() 方法返回。示例输入:
foo bar 2.00 foo foo
bar bar foo 6.34
我需要在TextView 中设置文本,其中可以单击数字 2.00 和 6.34 并调用函数,但其他文本保持不变。
感谢任何帮助
【问题讨论】:
android.text.style.ClickableSpan可以解决你的问题。
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);
【讨论】: