Question

I am using Linkify(text, pattern, scheme) to identify regular expressions in text presented in a dialog box. I would like the links to lead the user to other parts of my program.

A bit of background:

My app is a dictionary-style app. A ListView of terms are hashed to a list of definitions. When the user taps a term, the definition pops up in an AlertDialog. Some of those definitions themselves actually contain other terms. Example:

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

In the above case, the user would be able to click on the word 'cat', which should cause the dialog box to close, and in its place the definition of 'cat' should appear.

The problem is, the only documentation for Linkify() talks of opening web URLs. I need the link to indicate to the program that it needs to go to another definition.

Currently, I call definitions like this:

  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
    }

How could I make the Linkify() link call up another AlertDialog?

Was it helpful?

Solution

I think you need to use ClickableSpan. In OnClick method you can set the functionality, you want to achieve.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top