【问题标题】:Linkify - Linking scheme for non-web (internal) event controlLinkify - 用于非 Web(内部)事件控制的链接方案
【发布时间】:2012-09-01 21:58:48
【问题描述】:

我正在使用 Linkify(text, pattern, scheme) 来识别对话框中显示的文本中的正则表达式。我希望这些链接能够引导用户访问我的程序的其他部分。

一点背景:

我的应用是字典式应用。术语的 ListView 被散列到定义列表中。当用户点击一个术语时,定义会在 AlertDialog 中弹出。其中一些定义本身实际上包含其他术语。示例:

term: "dog"
definition: "A mid-sized furry domesticated animal. Not to be confused with [cat]s."

在上述情况下,用户可以点击单词“cat”,这会导致对话框关闭,并在其位置出现“cat”的定义。

问题是,Linkify() 的唯一文档谈到了打开 Web URL。我需要该链接以指示程序需要转到另一个定义。

目前,我这样称呼定义:

  ListView lv = getListView();

  lv.setOnItemClickListener(new OnItemClickListener() { // when an item is clicked on...
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {

        // Linkify parameters
        Pattern pattern = Pattern.compile("\\[[^]]*]"); // defines the fact that links are bound by [square brackets]
        String scheme = ""; // *** THIS IS WHERE I NEED TO ADD A PROPER SCHEME ***

        AlertDialog alertDialog = new AlertDialog.Builder(ListProjectActivity.this).create(); // create a dialog box in memory
        alertDialog.setTitle(((TextView) view).getText()); // set title of dialog box to term name
        SpannableString definition = new SpannableString(dictionaryMap.get(((TextView) view).getText())); // grab the definition by checking against the dictionary map hash
        Linkify.addLinks(definition, pattern, scheme); // add links to definition
        alertDialog.setMessage(definition); // set dialog box message to term definition
        alertDialog.show(); // actually display the dialog box
    }

如何让 Linkify() 链接调用另一个 AlertDialog?

【问题讨论】:

    标签: android url-scheme linkify


    【解决方案1】:

    我认为您需要使用ClickableSpan。在 OnClick 方法中你可以设置你想要实现的功能。

    【讨论】:

    • ClickableSpan 不支持“长按”
    猜你喜欢
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多