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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:09:29+00:00 2026-06-07T22:09:29+00:00

I am trying to change only one (maybe more) ListView row based on specific

  • 0

I am trying to change only one (maybe more) ListView row based on specific condition. I have read many answers on similar questions and tons of other tutorials but I am not able to make anything.

Exactly what I want to achieve is to have row background (easier version) or row picture (I think harder version) set different than others when row from SQLite is set at specific value.

I have got Activity that extends ListActivity and I am setting the ListView adapter like this:

private void refreshList() {
    mySQLiteAdapter = new MyDBAdapter(this);
    mySQLiteAdapter.open();
    String[] columns = { MyDBAdapter.KEY_TITLE, MyDBAdapter.KEY_GENRE,
            MyDBAdapter.KEY_PRICE, MyDBAdapter.KEY_ID };

    Cursor contentRead = mySQLiteAdapter.getAllEntries(false, columns,
            null, null, null, null, MyDBAdapter.KEY_TITLE, null);

    SimpleCursorAdapter adapterCursor = new SimpleCursorAdapter(this,
            R.layout.row, contentRead, columns, new int[] {
                    R.id.text1, R.id.detail });

    this.setListAdapter(adapterCursor);
    mySQLiteAdapter.close();
}

This function is called in onCreate method and in onResume. I want to set different color/image of row where value from column MyDBAdapter.KEY_PRICE is equal to 5. The R.layout.row is my xml file with row design.

Maybe someone can help me with this? Or at least show tutorial describing it?

  • 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-07T22:09:30+00:00Added an answer on June 7, 2026 at 10:09 pm

    Simply extend SimpleCursorAdapter and override bindView():

    public class MyAdapter extends SimpleCursorAdapter {
        public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        }
    
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            super.bindView(view, context, cursor);
            if(cursor.getLong(cursor.getColumnIndex(MyDBAdapter.KEY_PRICE)) == 5)
                view.setBackgroundColor(0xff00ff00);
            else // this will be the default background color: transparent
                view.setBackgroundColor(0x00000000);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to change my many to many script field to use FilteredSelectMultiple
I'm trying to write a program to automate one of my more boring and
I may be trying to get too fancy on this one. I have a
Im trying this, but when i press it it dont changes, it only displays
I'm trying change an input mask for textbox when the the check box has
Am trying to change the button frame according to the orientation change but button
I´m trying to change a spring jsp example to use freemarker. I changed all
im trying to change font globally for whole application, the problem is, i am
I am trying to change the color of my draggable if it is reverting
I'm trying to change some text in a .CSV file. StreamReader sReader = new

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.