我正在嘗試使用3種不同佈局的ExpandabelistView。子位置可擴展列表視圖返回錯誤的值?
的結構是這樣的: 如果是第一次佈局視圖加載應該firstview.xml 和他們,如果這是一個連孩子應該加載甚至有觀點認爲,如果是奇數應載入另一個。
問題是,它有時有效,但有時它不。我試圖記錄childPosition,但每次都會得到不同的值。孩子的位置值在同一個孩子內返回到0。
這裏是我的getChildView()
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final String children = (String) getChild(groupPosition, childPosition);
TextView textTitle;
TextView textDescription;
if(convertView == null) {
if(childPosition == 0) {
convertView = inflater.inflate(R.layout.listrow_first_element, null);
} else if(childPosition % 2 != 0) {
convertView = inflater.inflate(R.layout.listrow_details, null);
} else {
convertView = inflater.inflate(R.layout.listrow_details_color2, null);
}
}
textTitle = (TextView) convertView.findViewById(R.id.titleView);
textDescription = (TextView) convertView.findViewById(R.id.descriptionView);
textTitle.setText(getChildString(childPosition));
textDescription.setText(children);
return convertView;
}
這裏是logcat的孩子們位置返回到我的代碼:
03-04 19:26:10.181 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 0
03-04 19:26:10.181 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 1
03-04 19:26:10.181 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 2
03-04 19:26:10.191 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 3
03-04 19:26:10.191 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 4
03-04 19:26:10.191 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 5
03-04 19:26:10.191 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 6
03-04 19:26:10.201 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 7
03-04 19:26:10.201 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 0
03-04 19:26:10.211 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 1
03-04 19:26:10.211 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 2
03-04 19:26:10.221 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 3
03-04 19:26:10.221 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 4
03-04 19:26:10.221 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 5
03-04 19:26:14.876 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] DisableGcInRange: toleranceRange = 4
03-04 19:26:14.876 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] disableGcInRange: Left 4194304 bytes to trigger GC (current size:32409816 bytes)
03-04 19:26:15.096 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 6
03-04 19:26:16.207 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] nativeRestoreGc
03-04 19:26:19.601 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] DisableGcInRange: toleranceRange = 4
03-04 19:26:19.601 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] disableGcInRange: Left 4194304 bytes to trigger GC (current size:32414792 bytes)
03-04 19:26:19.661 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 7
03-04 19:26:20.001 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 1
03-04 19:26:20.121 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 0
03-04 19:26:20.952 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] nativeRestoreGc
03-04 19:26:21.032 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] DisableGcInRange: toleranceRange = 4
03-04 19:26:21.032 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] disableGcInRange: Left 4194304 bytes to trigger GC (current size:32416096 bytes)
03-04 19:26:21.152 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] nativeRestoreGc
03-04 19:26:23.114 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] DisableGcInRange: toleranceRange = 4
03-04 19:26:23.114 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] disableGcInRange: Left 4194304 bytes to trigger GC (current size:32416096 bytes)
03-04 19:26:23.154 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 6
03-04 19:26:23.214 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 7
03-04 19:26:23.555 23283-23283/com.gabilheri.insuringmylife D/Child Position:﹕ 0
03-04 19:26:23.645 23283-23283/com.gabilheri.insuringmylife D/dalvikvm﹕ [GC Control] nativeRestoreGc
什麼是支持你的組/子數據的數據結構?你可以發佈getChild和getGroup的代碼嗎? – WindsurferOak