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 7542371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:08:54+00:00 2026-05-30T08:08:54+00:00

I am trying to show in an android AlertDialog some text and some words

  • 0

I am trying to show in an android AlertDialog some text and some words to be clickable opening a web page. I am doing something wrong with it cause it does not open the link i am telling him and the hole text is clickable, which i am trying to avoid….
This is my code:

final SpannableString s = new SpannableString(
                        Html.fromHtml("<br><a href=\"http://google.com\">a new link</a>")
                        );

        final TextView tx1 = new TextView(this);
        tx1.setText(getString(R.string.librarytextpart1) 
                + s
                + getString(R.string.librarytextpart2));
        tx1.setAutoLinkMask(RESULT_OK);
        tx1.setMovementMethod(LinkMovementMethod.getInstance());

        Linkify.addLinks(s, Linkify.ALL);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.library))
                .setCancelable(false)
                .setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                            }
                        })

                .setView(tx1).show();

When clicked on the SpannableString text in dialog, it shows the entire text is clickable … and still does not open a webpage. For sure I don’t understand something right from the documentation, but don’t see what. Can you help, please?

  • 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-05-30T08:08:56+00:00Added an answer on May 30, 2026 at 8:08 am

    With Html.fromHtml() you receive the already formatted HTML text from a given String.

    Applied to your case this would result in a “a new link” – but the “href” below is ignored by the Alert Dialog as it is not displaying HTML. So the linkifier does nothing on your code. Try commenting it out – the behaviour will keep the same.

    With the Linkifier, you are able to turn arbitrary patterns of text (RegExes) into clickable Links. You may append for example a String matching your Regular Expression to a predefined “base” content URI. So it does not only work for Websites but for every Content URI used on Android. For more Info on that refer to the Google DevSite.

    You could use the Linkifier without Regular Expressions, there are a some standard patterns included. These are matching eMail-adresses, phone numbers, map coordinates or a website. So in order to make your solution work:

    1. Set the spannable String to a normal URL (no HTML stuff)
    2. Just add Links for the Type “WEB_URLS” (Linkify.WEB_URLS) (Linkify.ALL will “search” for all predefined patterns as stated above)

    And it will work.

    I adjusted your code, now in the AlertWindow, the URL “www.google.com” should be clickable:

    final SpannableString s = new SpannableString("www.google.com");
    
        final TextView tx1 = new TextView(this);
        tx1.setText(getString(R.string.librarytextpart1) 
                + s
                + getString(R.string.librarytextpart2));
        tx1.setAutoLinkMask(RESULT_OK);
        tx1.setMovementMethod(LinkMovementMethod.getInstance());
    
        Linkify.addLinks(s, Linkify.WEB_URLS);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.library))
                .setCancelable(false)
                .setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                            }
                        })
    
                .setView(tx1).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my android application I am trying to show a Loading... text which will
I am trying to create an android app which will show multiple web urls
I am working on android project and I am trying to show an AlertDialog
I am trying to show an alert with two edittext fields in Android. The
I'm trying to show a list of data in an android activity. Normally anyone
I'm trying to test an Activity in android which will show a ProgressDialog and
I'm trying to show a list of links (in index.html) to text files in
I am trying to show a alertdialog but i keep getting this error 01-24
I'm trying out some game engines for android and came across cocos2d-android-1 . I've
I am trying to implement Camera application in android,and i got some code from

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.