gpt4 book ai didi

android - 如何更改 ListView 特定项目的颜色?

转载 作者:太空宇宙 更新时间:2023-11-03 10:20:30 25 4
gpt4 key购买 nike

我有一个自定义列表适配器如下:

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;
}

现在我需要基于保存在“baseOnThis”的数组列表中的数据库值来更改 ListView 项目的颜色,但我不能。有什么想法我应该怎么做?请让我知道如果我的问题是错误的并且不要减去我

最佳答案

试试这个

if(position == 3){
holder.SecondHemistich.setTextColor(this.context.getResources().getColor(R.color.color1));
}

关于android - 如何更改 ListView 特定项目的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23755522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com