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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:08:55+00:00 2026-05-21T22:08:55+00:00

I have a ListView with some elements and I want to change the background

  • 0

I have a ListView with some elements and I want to change the background of the row depending on their type in the database. What I got is a SimpleCursorAdapter instance and it’s function adapter.setViewBinder(...). But it seems, that I can’t access the LinearLayout of a row. Here’s the code:

final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.day, c, new String[] { "name_con", "start", "end",
                    "type", "prof", "room" }, new int[] { R.id.subjectName,
                    R.id.subjectStart, R.id.subjectEnd, R.id.subjectType,
                    R.id.subjectProf, R.id.subjectRoom });

    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int column) {
            switch (view.getId()) {
            case R.id.subjectName:
                final String colNameName = cursor.getString(1);
                ((TextView) view).setText(colNameName);

                return true;
            case R.id.subjectStart:
                final int colNameStart = cursor.getInt(2);

                Date dStart = new Date(colNameStart * 1000);
                SimpleDateFormat sdfStart = new SimpleDateFormat(
                        "HH:mm", Locale.getDefault());
                String startString = sdfStart.format(dStart);

                ((TextView) view).setText(startString);

                return true;
            case R.id.subjectEnd:
                final int colNameEnd = cursor.getInt(3);

                Date dEnd = new Date(colNameEnd * 1000);
                SimpleDateFormat sdfEnd = new SimpleDateFormat(
                        "HH:mm", Locale.getDefault());
                String EndString = sdfEnd.format(dEnd);

                ((TextView) view).setText(EndString);

                return true;
            case R.id.subjectType:
                final int colNameType = cursor.getInt(4);

                switch(colNameType){
                case 0:
                    ((TextView) view).setText(R.string.practice);
                    break;
                case 1:
                    ((TextView) view).setText(R.string.course);
                    break;
                case 2:
                    ((TextView) view).setText(R.string.practica);
                    break;
                case 3:
                    ((TextView) view).setText(R.string.seminar);
                }

                return true;
            case R.id.subjectProf:
                final String colNameProf = cursor.getString(5);
                ((TextView) view).setText(colNameProf);

                return true;
            case R.id.subjectRoom:
                final String colNameRoom = cursor.getString(6);
                ((TextView) view).setText(colNameRoom);

                return true;
            case R.id.dayCell:
                ((LinearLayout)view).setBackgroundColor(Color.WHITE);
            default:
                return false;
            }
        }
    });

    this.setListAdapter(adapter);
  • 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-21T22:08:56+00:00Added an answer on May 21, 2026 at 10:08 pm

    You should be able to do something like:

    switch (view.getId()) {
                case R.id.subjectName:
                    final String colNameName = cursor.getString(1);
                    ((TextView) view).setText(colNameName);
                    ((LinearLayout)view.getParent()).setBackgroundResource(<resource id>);
                    return true;
    

    EDIT: for efficiency, you’ll probably only want to do it in one of the ViewBinder passes, and you’d need to be sure its a LinearLayout that’s created in R.layout.day or you’ll end up with a ClassCast exception.

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

Sidebar

Related Questions

i want to display some information in a listview using the GridView. i have
Env.: VS 2008, .NET 2.0, WinForms I have a listview in Tile mode. Some
I have a ListView inside of an Update Panel and wanted to change the
I have a listview with a DataTemplate that has a ComboBox. I want the
I have one ListView which is showing me some data through an array (which
I have a ListView control, and I'm trying to figure out the easiest/best way
I have a ListView which sometimes I need to put around 10000 items in.
I have a ListView in WPF that is databound to a basic table that
I have a ListView containing file names. These file names need to be draggable
I have a ListView on a page that displays a list of widgets. When

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.