如何更改列表视图的背景? [英] How to change the background of the list view?

查看:67
本文介绍了如何更改列表视图的背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数组列表数据

John

John

Jack

Peter

派克



重复的名字必须在列表视图中有不同的背景



怎么办?



我尝试过:



ArrayList< listitem> data =

(ArrayList< listitem>)bundle.getSerializable(value);



sentItems = data; //姓John,John,Jack ....



final List< listitem> duplicates = new ArrayList< listitem>();

Set< listitem> listitemSet = new TreeSet< listitem>(new Comparator< listitem>(){

@Override

public int compare(ListItem o1,ListItem o2){

返回o1.getTitle()。compareTo(o2.getTitle());

}

});

for(ListItem c:sentItems)

{

if(!listitemSet.add(c))

{

重复。加(C);

}

}

my array list data
John
John
Jack
Peter
Parker

the repeated names must have different background in the list view

how to do that?

What I have tried:

ArrayList<listitem> data=
(ArrayList<listitem>)bundle.getSerializable("value");

sentItems = data; //names John,John,Jack....

final List<listitem> duplicates = new ArrayList<listitem>();
Set<listitem> listitemSet = new TreeSet<listitem>(new Comparator<listitem>() {
@Override
public int compare(ListItem o1, ListItem o2) {
return o1.getTitle().compareTo(o2.getTitle());
}
});
for(ListItem c : sentItems)
{
if(!listitemSet.add(c))
{
duplicates.add(c);
}
}

推荐答案

在你的适配器的 getView()方法,调用转换后的视图的 setBackgroundColor()方法。
In your adapter's getView() method, call the converted view's setBackgroundColor() method.


这篇关于如何更改列表视图的背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆