如何改变列表视图的特定项目的颜色? [英] How change color of specific item of listview?
本文介绍了如何改变列表视图的特定项目的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个customlistadapter如下:
I have a customlistadapter as follow:
public class CustomListViewAdapter2 extends ArrayAdapter<RowItem> {
List<Integer> baseOnThis;
public CustomListViewAdapter2(Context context, int resourceId,
List<RowItem> items, ArrayList<Integer> ids) {
super(context, resourceId, items);
this.context = context;
baseOnThis= ids;
}
/* private view holder class */
private class ViewHolder {
TextView firstHemistich;
TextView SecondHemistich;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
RowItem rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.hemistich_rows, null);
holder = new ViewHolder();
holder.firstHemistich = (TextView) convertView
.findViewById(R.id.title);
holder.SecondHemistich = (TextView) convertView
.findViewById(R.id.desc);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.firstHemistich.setText(rowItem.getTitle());
holder.SecondHemistich.setText(rowItem.getDesc());
return convertView;
}
现在我需要了解它保存在ArrayList的baseOnThis更改列表视图项的颜色,但我不能将数据库价值基础。是否有任何想法,我应该怎么办呢?
请让我知道,如果我的问题是错误的,没有负我。
now I need base on the database value that saved on Arraylist of "baseOnThis" change the color of item of listview but I can't. Is there any idea how should I do this? Please let me know if my question is wrong and don't minus me
推荐答案
试试这个
if(position == 3){
holder.SecondHemistich.setTextColor(this.context.getResources().getColor(R.color.color1));
}
这篇关于如何改变列表视图的特定项目的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文