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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:05:39+00:00 2026-05-27T20:05:39+00:00

I’m pretty new to android, Java and sqlite. For my first program I’m creating

  • 0

I’m pretty new to android, Java and sqlite. For my first program I’m creating a program that will take user input and place in predefined text.

Example: “text” string1 “more text” string2 “even more text” etc

My text will be one color and strings will display in another color.

I’m using sqlite to seperate my data and code and this is where I hit a wall. Trying to find help on how I will be able to combine my above text into one row/column in my database table.

Using only one above example i could get this up and running. But there will be 50+ of above example for release making a database a must especially when I want to add more after release.

  • 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-27T20:05:39+00:00Added an answer on May 27, 2026 at 8:05 pm

    Most probably you’ve read up on SpannableStringBuilder, which allows you to add color to the text in your TextView’s content. Check out the code below:

    SpannableStringBuilder ssb = new SpannableStringBuilder(<your text>);
    ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    
    ssb.setSpan(fcs, 0, ssb.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(ssb); 
    

    The code above will work in most cases, however what you want is to have different alternating colors on a single TextView. Then you should do the following:

    String text = your_text + text_from_database;
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    ForegroundColorSpan fcs2 = new ForegroundColorSpan(Color.rgb(0, 255 0));
    
    ssb.setSpan(fcs, 0, your_text, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(fcs2, your_text.length(), ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(ssb);
    

    The above code will now work, but you’ll notice that if you add another text your_another_text and want to use the previous fcs instance for a second time, the previously colored your_text will now lose its formatting (color). This time you’ll need to create another ForegroundColorSpan fcs3 to format the third part of the SpannableStringBuilder. The key here is to use a character style in a setSpan method only once. See below:

    String testTest = "abcdefgh";
    String testTest2 = "ijklmnop";
    String testTest3 = "qrstuvwxyz";
    
    SpannableStringBuilder ssb = new SpannableStringBuilder(testTest+testTest2+testTest3);
    ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    ForegroundColorSpan fcs2 = new ForegroundColorSpan(Color.rgb(0, 255, 0));
    ForegroundColorSpan fcs3 = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    
    
    ssb.setSpan(fcs, 0, testTest.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    ssb.setSpan(fcs2, testTest.length(), (testTest+testTest2).length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    ssb.setSpan(fcs3, (testTest+testTest2).length(), ssb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    
    test.setText(ssb);
    

    This method is good if you know you have a fixed number of String elements in your SpannableStringBuilder. If you have wish to have a TextView of dynamic length and number of elements, you need to do this in a different approach. What worked for me was to convert each string element into a SpannableString, use setSpan, and append it to the TextView. This is useful if you’re using a loop to build your TextView.

    TextView test = (TextView)findViewById(R.id.test);
    
    String testTest = "abcdefgh";
    String testTest2 = "ijklmnop";
    String testTest3 = "qrstuvwxyz";
    
    SpannableString ssb = new SpannableString(testTest);
    ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    ForegroundColorSpan fcs2 = new ForegroundColorSpan(Color.rgb(0, 255, 0));
    ForegroundColorSpan fcs3 = new ForegroundColorSpan(Color.rgb(255, 0, 0));
    
    ssb.setSpan(fcs, 0, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    test.setText(ssb);
    
    SpannableString ssb2 = new SpannableString(testTest2);
    ssb2.setSpan(fcs2, 0, ssb2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    test.append(ssb2);
    
    SpannableString ssb3 = new SpannableString(testTest3);
    ssb3.setSpan(fcs3, 0, ssb3.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    test.append(ssb3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.