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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:40:53+00:00 2026-05-26T17:40:53+00:00

I have a function to build clickable tags for a textview. It goes as

  • 0

I have a function to build clickable tags for a textview. It goes as follows:

    private CharSequence tagsBuilder(String text, String token) {
    SpannableStringBuilder builtTags = new SpannableStringBuilder();
    int start = 0, end = 0;

    for(int i = 0; i < 5; i++) {
        start = 0;
        end = text.indexOf(token, 0);

        try {
            if(start < end) {
                SpannableStringBuilder ssb = new SpannableStringBuilder(text.substring(start, end));
                ssb.setSpan(new ClickableSpan() {
                    @Override
                    public void onClick(View v)
                    {

                        Log.i("DEBUGTAG", "Span clicked - " + ((TextView) v).getText());
                    }
                }, start, end, 0);

                builtTags.append(ssb);
                builtTags.append(" ");
                text = text.substring(end + 1);
            }
        } catch (IndexOutOfBoundsException e) {
            break;
        }
    }

    return builtTags;
}

I can see the textview with 5 individually clickable tags. But the problem is, the Log that prints for any tag that is clicked is whole text of the textview.

Am I doing something wrong here? How do I get the text of individual tags that were clicked.

  • 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-26T17:40:53+00:00Added an answer on May 26, 2026 at 5:40 pm

    Your log line is the following:

    Log.i("DEBUGTAG", "Span clicked - " + ((TextView) v).getText());
    

    That logs the contents of the TextView. So… you get the text of the TextView. If you want to get token in there, you’ll have to copy that in.

    Here’s something you can try:

    private CharSequence tagsBuilder(String text, final String token) {
    SpannableStringBuilder builtTags = new SpannableStringBuilder();
    int start = 0, end = 0;
    
    for(int i = 0; i < 5; i++) {
        start = 0;
        end = text.indexOf(token, 0);
    
        try {
            if(start < end) {
                SpannableStringBuilder ssb = new SpannableStringBuilder(text.substring(start, end));
                ssb.setSpan(new ClickableSpan() {
                    private String mText = token;
                    @Override
                    public void onClick(View v)
                    {
    
                        Log.i("DEBUGTAG", "Span clicked - " + mText);
                    }
                }, start, end, 0);
    
                builtTags.append(ssb);
                builtTags.append(" ");
                text = text.substring(end + 1);
            }
        } catch (IndexOutOfBoundsException e) {
            break;
        }
    }
    
    return builtTags;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have build a function: string removeFile(HttpContext context,HttpRequest r) { dynamic d = new
I have a variable that I'm using to build a JavaScript function call, and
I have a function sincos_Q15_asm() in assembly, in file sincos_p5sh.asm with directives as follows:
I have a function to build a rss feed with PHP: function createRSS() {
I'm working on a Titanium app and have build a function to run sqlite
I have a function in Axapta as follows: static client XMLDocument GetXmlData() { XMLDocument
I have a search function de build. We are using pure ASP.NET w\ VB.NET
I have a function which signature is String -> String -> IO (Maybe String)
Hi I have build a function to accept list of images as an arguments.
I have a javascript function that is being built to animate the collapse of

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.