Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:59:20+00:00 2026-06-11T05:59:20+00:00

I have added links to text that is surrounded by [square brackets] in a

  • 0

I have added links to text that is surrounded by [square brackets] in a popup dialog box. The links however, are not clickable (nothing happens when they are pressed). I can’t work out why(!)

Here is my dialog box activity:

public void popupDefinition(CharSequence term, LinkedHashMap<String, String> dictionaryMap){
    SpannableString definition = new SpannableString(dictionaryMap.get(term)); // grab the definition by checking against the dictionary map hash
    Linkify.addLinks(definition, pattern, scheme); // find text in square brackets, add links

    AlertDialog alertDialog = new AlertDialog.Builder(ListProjectActivity.this).create(); // create a dialog box
    alertDialog.setMessage(definitionFormatted); // set dialog box message
    alertDialog.show(); // actually display the dialog box
    }

‘scheme’ and ‘pattern’ are defined earlier, as follows:

final static Pattern pattern = Pattern.compile("\\[[^]]*]"); // defines the fact that links are bound by [square brackets]
final String scheme = "http://example.com/"; // THIS IS NOT WORKING

Why, when I tap the links that appear (they appear nicely underlined in blue), do they not cause any response?

I’m not actually trying to launch URL links (I’ll be redirecting the ACTION_VIEW intent when it does occur), but I need to confirm that some sort of response is happening before I get to that…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:59:21+00:00Added an answer on June 11, 2026 at 5:59 am

    I’m not actually trying to launch URL links

    Since you don’t need to use URLs, don’t bother with trying to create a custom Linkify scheme since it only creates URLSpans. You simply want to start an Activity from a keyword in a TextView. As I stated in one of your similar, but not duplicate, questions I would use a custom span, introducing ActivitySpan:

    public class ActivitySpan extends ClickableSpan {
        String keyword;
        public ActivitySpan(String keyword) {
            super();
            this.keyword = keyword;
        }
    
        @Override
        public void onClick(View v) {
            Context context = v.getContext();
            Intent intent = new Intent(context, AnotherActivity.class);
            intent.putExtra("keyword", keyword);
            context.startActivity(intent);
        }
    }
    

    There are no bells or whistles here, this span takes a [keyword] that you surrounded in brackets and passes it to the another Activity.

    While I don’t like the idea of using Linkify because of URLSpans, its pattern matching and span creation is great, so I copied and modified it:

    private void addLinks(TextView textView, Pattern pattern) {
        SpannableString spannable = SpannableString.valueOf(textView.getText());
        Matcher matcher = pattern.matcher(spannable);
    
        // Create ActivitySpans for each match
        while (matcher.find())
            spannable.setSpan(new ActivitySpan(matcher.group()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    
        // Set new spans in TextView
        textView.setText(spannable);
    
        // Listen for spannable clicks, if not already
        MovementMethod m = textView.getMovementMethod();
        if ((m == null) || !(m instanceof LinkMovementMethod)) {
            if (textView.getLinksClickable()) {
                textView.setMovementMethod(LinkMovementMethod.getInstance());
            }
        }
    }
    

    As a note, this method doesn’t remove the [brackets] surrounding each keyword, but you can easily do this in the while-loop.

    To use this, simply pass a TextView and Pattern to addLinks() in onCreate() and Voila!


    A working example for you:

    public class Example extends Activity {
        Pattern pattern = Pattern.compile("\\[[^]]*]");
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            popupDefinition("Example: A [pattern] or [model], as of something to be [imitated] or [avoided]");
        }
    
        // It seems like you can call "popupDefinition(dictionaryMap.get(term));" rather than pass both.  
        public void popupDefinition(String string){
            SpannableString spannable = new SpannableString(string);
            Matcher matcher = pattern.matcher(spannable);
    
            // Create ActivitySpans for each match
            while (matcher.find())
                spannable.setSpan(new ActivitySpan(matcher.group()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    
            // Create a new TextView with these spans and enable the clickable links
            TextView textView = new TextView(this);
            textView.setText(spannable);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
    
            // Create and display an AlertDialog with this TextView
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setView(textView)
                    .create(); 
            alertDialog.show(); 
        }
    
    
        public class ActivitySpan extends ClickableSpan {
            String keyword;
            public ActivitySpan(String keyword) {
                super();
                this.keyword = keyword;
            }
    
            @Override
            public void onClick(View v) {
                Context context = v.getContext();
                Toast.makeText(context, keyword, Toast.LENGTH_SHORT).show();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two fields reference link and reference text that are added dynamically in
I have a ChildWindow. In this childwindow, I have added properties that link to
I have added an extra field Specification in Catalog->Product->Data tab. This text is stored
I have added a checker to ensure that all fields in a form have
I have text links in a paragraph which is replaced using Cufon. For some
I have several similar links that trigger different navigation divs to appear. I am
I have a list of links that should be displayed inline. The thing is
I have a simple jQuery function that resizes text areas, and I want it
I have dropdown menus that look like this: However, I wanted a div element
I have a view. the view has a function that returns a text string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.