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

  • Home
  • SEARCH
  • 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 3979882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:28+00:00 2026-05-20T05:13:28+00:00

I have a app that gets a string from a database and it sets

  • 0

I have a app that gets a string from a database and it sets to a label. Now i want that label to underline one word such as “This word should be underlined.” and i want to be able to click on that underline word and get its value. So do i set it up before i send it to the database or after. Thanks for any help. I tried code below and each line is highlighted because of the for loop. please help

SpannableStringBuilder builder = new SpannableStringBuilder();
            for(int i=0;i<ListClass.getLatestActivity().size();i++){
                String myString  = ListClass.getLatestActivity().get(i);
                builder.append(myString);
                String substringThatShouldBeClickable = myString.substring(0,myString.indexOf(' ')).trim();
                MySpan span = new MySpan(substringThatShouldBeClickable);
                span.setOnMySpanClickListener(mySpanOnClickListener);

                int start = 0;
                int end = builder.length();

                builder.setSpan(span, start, end, 0);
                builder.append("\n" + "\n") ;
            }
            RAInfo.setText(builder);    
            RAInfo.setMovementMethod(LinkMovementMethod.getInstance());
  • 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-20T05:13:29+00:00Added an answer on May 20, 2026 at 5:13 am

    Ok, so there’s a few things you’ll need to do. They way to accomplish this is by using a span inside of the TextView.

    First you’ll need a class that extends ClickableSpan:

    public class MySpan extends ClickableSpan {
        public interface OnMySpanClickListener {
                public void onMySpanClick(String tag);
        }
    
        private final String myData;
        private OnMySpanClickListener mOnMySpanClickListener;
    
        public MySpan(String tag) {
                super();
                if (tag == null) {
                        throw new NullPointerException();
                }
                myData = tag;
        }
    
        @Override
        public void onClick(View widget) {
                if (mOnMySpanClickListener != null) {
                    mOnMySpanClickListener.onMySpanClick(myData);
                }
        }
    
        public OnMySpanClickListener getOnMySpanClickListener() {
                return mOnMySpanClickListener;
        }
    
        public void setOnMySpanClickListener(OnMySpanClickListener onMySpanClickListener) {
                mOnMySpanClickListener = onMySpanClickListener;
        }
    }
    

    In your Activity, you’ll set the text of the TextView like this:

    String myString = getFromDatabase();    
    
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(myString);
    
    //You'll need to call the constructor for MySpan with only the value of the part
    //of the string that you want to work with ("Bob" in the example), however you 
    //determine that.
    String substringThatShouldBeClickable = getMySubstring(myString);  //"Bob"
    MySpan span = new MySpan(substringThatShouldBeClickable);
    span.setOnMySpanClickListener(mySpanOnClickListener);
    
    //start and end control the range of characters in the string that are clickable,
    //so modify this part so it only underlines the characters you want clickable
    int start = 0;
    int end = bulider.length();
    
    builder.setSpan(span, start, end, 0);
    
    label.setText(builder);
    label.setMovementMethod(LinkMovementMethod.getInstance());
    

    Finally, you’ll need a handler for the click events on the span:

    MySpan.OnMySpanClickListener mySpanOnClickListener = new MySpan.OnMySpanClickListener() {
        public void onMySpanClick(String tag) {
            //Here is where you'll do your work with the value in the String "tag"
        }
    };
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a NET app that gets installed to the Program Files folder. The
I have a web app that gathers some data from the user and saves
I have an app that does a query to a database.....asking for GPS data
I have an app that needs to open a new window (in the same
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd
I have an app that is failing on the install. The vendor says I
I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my
I have an app that needs to handle very large strings between a SQL
I have an app that I'm writing a little wizard for. It automated a

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.