I am using Jeff Sharkey’s SeparatedListAdapter and I would like to set the text color, but I’m not sure how.
To give you some background on his adapter, he subclassed a BaseAdapter similar to a simple Android list. So, I tried to set the text color in the getView() method like this (Your can see my attempt in between the commented section):
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
int sectionnum = 0;
for(Object section : this.sections.keySet()) {
Adapter adapter = sections.get(section);
int size = adapter.getCount() + 1;
// check if position inside this section
if(position == 0) return headers.getView(sectionnum, convertView, parent);
if(position < size)
{
/***** I added this section to try to set the text color ***/
TextView captionTV = (TextView)adapter.getView(position, convertView, parent).findViewById(R.id.list_complex_caption);
captionTV.setTextColor(R.color.black;);
TextView titleTV = (TextView)adapter.getView(position, convertView, parent).findViewById(R.id.list_complex_title);
titleTV.setTextColor(R.color.black;);
/***** end add *****/
return adapter.getView(position - 1, convertView, parent);
}
// otherwise jump into next section
position -= size;
sectionnum++;
}
return null;
}
But what happens is that it sets the text color for the first cell, but does not set it for the rest.
Any ideas?
Hm. Nifty adapter.
The first thing to note here – modifying
Views in the way you’re doing is something best left to the layouts you use in the various section adapters, i.e. if you want black text, use an item layout that has black text.To do it in code anyway you should not repeatedly call
#getView(int, View, ViewGroup)on the sub-section adapters, instead do like this: