我正在使用Jeff Sharkey's SeparatedListAdapter,我想设置文字颜色,但我不知道如何。如何在SeparatedListAdapter中设置文本颜色?
为了给你一些关于他的适配器的背景知识,他将一个类似于简单Android列表的BaseAdapter分类。所以,我试图设置文本颜色在getView()
方法是这样的(你可以看到我尝试在注释部分之间):
@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;
}
但是,什么情况是,它设置文本颜色为第一小区,但没有为其余的设置。
任何想法?
我通常会设置它在XML布局,但对于这个特殊的例子中,我有一个需要动态设置颜色,因为它不会停留在整个应用程序的生命周期是静态的。换句话说,它不会像我的例子那样保持黑色。无论如何,你的答案是完美的!很好的答案,我不能够感谢你。 – AngeloS 2012-01-05 18:41:11