Android:ListView的工作原理
例如,我的自定义ExpandableListAdapter扩展了BaseExpandableListAdapter,它有两个组Android:ListView的工作原理,android,Android,例如,我的自定义ExpandableListAdapter扩展了BaseExpandableListAdapter,它有两个组 public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = infalIn
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if (convertView == null) {
convertView = infalInflater.inflate(R.layout.rowgroup, parent, false);
}
s++;
Log.d("Index", String.valueOf(s));
return convertView;
}
第一个问题:为什么此代码总是以LogCat Index=1、Index=2、Index=3、,指数=10
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if (convertView == null) {
s++;
Log.d("Index", String.valueOf(s));
convertView = infalInflater.inflate(R.layout.rowgroup, parent, false);
}
return convertView;
}
第二个问题:为什么此代码将以LogCat Index=1、Index=2、Index=3的形式返回?我只有两组,不是三组。如果我再添加一个组,索引值将为4。我在convertView=infalInflater.inflate中设置了断点(R.layout.rowgroup,parent,false)行,我看到在开始和结束时执行了groupPosition==0的getGroupView
这是我的错还是应该是这样?我想了解为什么会发生这种情况=)
谢谢你的回答 我想我找到了答案=)在此之前,我不明白它是如何工作的