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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:07:27+00:00 2026-06-16T00:07:27+00:00

I retrieve from database my swimming performance. I would like to change background color

  • 0

I retrieve from database my swimming performance. I would like to change background color of one field according to his value. For example if i swimm 4 laps I want color background. I try this code that set background correctly but text disappears.

        String[] columns = new String[] { "swimm_pos", "swimm_date","swimm_lap", "swimm_stroke", "swimm_time", "swimm_media", "swimm_efficiency", "swimm_note" };
        int[] to = new int[] { R.id.row_counter, R.id.swimm_date, R.id.swimm_lap, R.id.swimm_stroke, R.id.swimm_time, R.id.swimm_medialap, R.id.swimm_efficiency, R.id.swimm_note};

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            this, 
            R.layout.contacto_list_item, 
            cursor, 
            columns, 
            to);

        adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
              if (view.getId() == R.id.swimm_lap)
                { 
                  int color = cursor.getInt(columnIndex);
                  String s = String.valueOf(color);
                  if (s.equals("4")) {
                  TextView tv = (TextView)view;
                  tv.setBackgroundColor(0xFF558866);}
                 return true;

            }
              return false;}

        });

And is also possible, when lap is equals to 4 set background color of another field, for example in my code: R.id.swimm_pos?
thank you.

  • 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-16T00:07:28+00:00Added an answer on June 16, 2026 at 12:07 am

    Returning true from ViewBinder implies that you are also binding the data to the View.

    But in your case you are not setting the text of R.id.swimm_lap.

    So add setText before return statement

    tv.setText(s);
    return true;
    

    Edit:
    For the second question suppose you want to change background of R.id.row_counter depending upon swim lap then add

    else if (view.getId() == R.id.row_counter){ 
     int color = cursor.getString(cursor.getColumnIndex("swimm_lap")); 
     if (s.equals("4")) {
         view.setBackgroundColor(0xFF558866);
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List<MyObject> that I retrieve from the database. However, I would like
How to retrieve value from database of SQLite onto UILabel but not in UITableView
Can anybody tell how to retrieve data from database like that of Facebook's notification
How to retrieve data from sqlite database? Getting return value zero. -(id)init{ if(self==[super init]){
I retrieve data from database like this: OleDbDataAdapter dataAdapter = new OleDbDataAdapter(SELECT * +
I want to retrieve from the database an array of values, one for each
I need to retrieve from the database a few large wave files and would
Which makes website more speedy retrieve data from a MySQL Database or test value
How to retrieve data from database to be displayed onto textbox. Like in my
Hi I am trying to retrieve values from database. I have a row which

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.