我现在用“getGroupView(int listPosition,boolean isExpanded,View convertView,ViewGroup parent)”方法进行为期一周的战斗。
我找到了一件关键的事情:
listPosition和convertView并不总是相关的
@Override
public View getGroupView(int listPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String listTitle = getGroup(listPosition).toString();
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_group, null);
}
TextView listTitleTextView = (TextView) convertView.findViewById(R.id.listTitle);
Item item = (Item) getGroup(listPosition); //Returns item from ArrayList
// The part behind && should ensure that no wrong passes happen. But they do anyway.
if (item.AllFound() && item.toString(Item.BASE_TITLE_FORMAT).equals(listTitleTextView.getText())){
//listTitleTextView.setBackgroundColor(Color.GREEN);
convertView.setBackgroundColor(Color.GREEN);
}
listTitleTextView.setText(listTitle);
return convertView;
}
这是什么:
但那只是我的胡言乱语。我愿意重写整件事。
那么如何根据创建它的Object更改ExpandableList的(标题)视图? (显然你不能依赖listPosition所以我应该如何检索正确的对象?)
答案 0 :(得分:0)
convertView将被重用,考虑所有情况
if (item.AllFound() && item.toString(Item.BASE_TITLE_FORMAT).equals(listTitleTextView.getText())){
//listTitleTextView.setBackgroundColor(Color.GREEN);
convertView.setBackgroundColor(Color.GREEN);
} else{
**Add code here to set backgroundColor**
}