如何更改列表视图的背景? [英] How to change the background of the list view?
问题描述
我的数组列表数据
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'sgetView()
method, call the converted view'ssetBackgroundColor()
method.
这篇关于如何更改列表视图的背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!