【问题标题】:Android - Make the numbers from a String clickable in TextView [duplicate]Android - 在TextView中使字符串中的数字可点击[重复]
【发布时间】: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 并调用函数,但其​​他文本保持不变。

感谢任何帮助

【问题讨论】:

  • 您可以对这些号码进行超链接//

标签: android tesseract


【解决方案1】:

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);

【讨论】:

    猜你喜欢
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多