Changing background on certain list items

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Changing background on certain list items

Postby flyshy514 » Sat Dec 13, 2008 8:19 am

I have certain elements in a SimpleCursorAdapter "list" whose background color I want to change when it is displayed in a list, the position id of those elements is contained in position[]. I assume I have oversimplified it. Please help.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         int k;
  2.  
  3.         int c = positionId.length;
  4.  
  5.         for(k = 0 ; k < c; k++){
  6.  
  7.                 if(position[k]<10){
  8.  
  9.                         View element = list.getView(position[k], null, null);
  10.  
  11.                         element.setBackgroundColor(R.color.gray);
  12.  
  13.                         list.bindView(element, this, listCursor);
  14.  
  15.                         element.invalidate();
  16.  
  17.                 }
  18.  
  19.         }
  20.  
  21.  
  22.  
  23.         setListAdapter(exercises);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
flyshy514
Freshman
Freshman
 
Posts: 2
Joined: Sat Dec 13, 2008 8:09 am

Top

Re: Changing background on certain list items

Postby Rahul » Mon Dec 15, 2008 12:08 pm

May be you can have a look at the URL below...Though not very similar you still can get an idea


Click here


flyshy514 wrote:I have certain elements in a SimpleCursorAdapter "list" whose background color I want to change when it is displayed in a list, the position id of those elements is contained in position[]. I assume I have oversimplified it. Please help.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         int k;
  2.         int c = positionId.length;
  3.         for(k = 0 ; k < c; k++){
  4.                 if(position[k]<10){
  5.                         View element = list.getView(position[k], null, null);
  6.                         element.setBackgroundColor(R.color.gray);
  7.                         list.bindView(element, this, listCursor);
  8.                         element.invalidate();
  9.                 }
  10.         }
  11.  
  12.         setListAdapter(exercises);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Postby MrSnowflake » Mon Dec 15, 2008 1:06 pm

Definately check the link Rahul posted.
The basic idea is to implement your own cursor adapter. There's a getView (or something like that) which allows you to pass different views for the current item.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests