从文本视图中的超链接打开一个对话框 - Android电子 [英] Open a dialog from a hyperlink on text view - Android

查看:100
本文介绍了从文本视图中的超链接打开一个对话框 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有就是把一些词的链接,一个TextView的方式,当我对这个词点击,对话是开放的。

There is a way to put a link in some words on a textView and when i click on this word, a dialog is open.

例:TextView的 - >词A - 字B - 字ç

Ex.: TextView --> Word A - Word B - Word C

当我在Word中点击,显示一个对话框,一些选项,当我在Word中单击C打开另一个对话框,另一个选项。

When i click on Word A, show a Dialog with some options, and when i click on Word C open another dialog with another options.

我检查这个环节,但我的问题不适合。

i checked this link but my problem dont fits.

<一个href=\"http://stackoverflow.com/questions/17850372/open-a-popup-alert-before-opening-a-link-in-the-browser-when-clicked-on-a-textvi\">Open在一个TextView 单击时在浏览器中打开链接之前弹出/警报

Open a popup/alert before opening a link in the browser when clicked on a textview

任何人都可以帮忙吗?

推荐答案

假设你都获得了这是一个测试 字符串,你希望显示对话框中的子并为子对话框乙测试。考虑以下方法:

Suppose you are given a "this is a test" String and you wish to show dialog A for the substring "this" and dialog B for the substring "test". Consider the following method:

private static void applySpan(SpannableString spannable, String target, ClickableSpan span) {
  final String spannableString = spannable.toString();
  final int start = spannableString.indexOf(target);
  final int end = start + target.length();
  spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

该方法采用中有一个 spannable ,第目标搜索发生和应用跨度它。显示 spannable 的TextView ,从活动说,你可以做到以下几点:

The method takes a spannable, searches for the first target occurrence in it and applies the span to it. To show the spannable in a TextView, say from an Activity, you could do the following:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final SpannableString spannable = SpannableString.valueOf("this is a test");
    applySpan(spannable, "this", new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            // show dialog A
        }
    });
    applySpan(spannable, "test", new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            // show dialog B
        }
    });

    final TextView textView = new TextView(this);
    textView.setText(spannableString);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    setContentView(textView);
}

这只是一个粗糙的例子,但它希望证明的方式来解决问题。

This is just a crude example, but it hopefully demonstrates a way to solve your problem.

这篇关于从文本视图中的超链接打开一个对话框 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆