我有ExpandableList,我分配给扩展BaseExpandableListAdapter.在这里,我实现了getChildView为每个子设置并返回View 的方法:
public View getChildView(int groupIndex, int childIndex, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout layout;
if (convertView == null) {
layout = (LinearLayout) LayoutInflater.from(MyApp.getContext()).inflate(R.layout.rooms_room_list_row, parent, false);
} else {
layout = (LinearLayout) convertView;
}
// Do some custom stuff with views on the layout
...
return layout;
}
Run Code Online (Sandbox Code Playgroud)
在调试时,我注意到getChildView每个孩子执行两次.传入的所有值(即groupIndex,childIndex,isLastChild)都是相同的...所以在第3组中,如果我有两个孩子,我会看到:
groupIndex = 3, childIndex = 0
然后
groupIndex = 3, childIndex = 1
然后它重复:
groupIndex = 3, childIndex = 0
最后:
groupIndex = 3, childIndex = 1
我的观点看起来很好,即该小组只列出了两个孩子,但为什么要做所有额外的工作呢?
更新和答案
似乎如果列表视图设置为高度,wrap_content则getChildView每个孩子将调用两次.更改高度fill_parent似乎可以解决此问题.
| 归档时间: |
|
| 查看次数: |
4185 次 |
| 最近记录: |