我想每個組像顯示不同的子佈局:Android的可擴展列表:組不同的佈局
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
switch (groupPosition){
case 0:
LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_row, null);
TextView tvPlayerName = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName.setText(arrChildelements[groupPosition][childPosition]);
break;
case 1:
LayoutInflater inflater1 = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater1.inflate(R.layout.child_row1, null);
TextView tvPlayerName1 = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName1.setText(arrChildelements[groupPosition][childPosition]);
break;
case 2:
LayoutInflater inflater2 = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater2.inflate(R.layout.child_row2, null);
TextView tvPlayerName2 = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName2.setText(arrChildelements[groupPosition][childPosition]);
break;
case 3:
LayoutInflater inflater3 = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater3.inflate(R.layout.child_row3, null);
TextView tvPlayerName3 = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName3.setText(arrChildelements[groupPosition][childPosition]);
break;
}
} return convertView;
}
我的問題是,而在羣體點擊,孩子名單羣體之間的相互變化。
有人可以告訴我,我做錯了什麼?
這是工作,如果去除(convertView == NULL)後,按預期工作正常。 我不明白,如果(convertView == null),我應該添加什麼內容,使其使用較少的內存。 – Kishore
我必須展示7種不同的佈局,這將很難把所有的觀點放在一個XML中。 – Kishore