1
例如我有我的自定義ExpandableListAdapter擴展BaseExpandableListAdapter,它有兩個組。Android:ListView如何工作
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的指數= 1總是返回,指數= 2,指數= 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的指數= 1返回,指數= 2,指數= 3?我只有2個組,而不是3個。如果我再添加一個組,則索引值將爲4.我在中設置了斷點convertView = infalInflater.inflate(R.layout.rowgroup,parent,false);線,我看到getGroupView與groupPosition == 0在開始和結束時執行。
這是我的錯誤還是應該是?我想了解爲什麼發生這種情況=)
感謝您的答案!