나는 ExpandableListView를 가지고 있으며 그것에 커스터마이징 된 BaseExpandableAdapter를 설정하고있다. 내 질문은, 내가 그 때마다 getChildView()에 그것을 부풀게하기보다는 어댑터 자체의 생성자에 표시하려는 레이아웃 (XML)을 부 풀릴 수 있습니까? 각 확장 가능 목록과 함께 표시 할 이미지를 동적으로 변경하여 getChildView()에서 선택합니다. 코드는 여기에 있습니다.어댑터의 생성자에서 XML 파일을 팽창시키기
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private LayoutInflater mInflater;
GridLayout gl = null;
HorizontalScrollView hScrl;
public MyExpandableListAdapter (ArrayList<SensorType> parentGroup, Context context) {
mContext = context;
mInflater = LayoutInflater.from(mContext);
View view = infalInflater.inflate(R.layout.expandlist_items, null);
gl = (GridLayout) view.findViewById(R.id.gl);
hScrl = (HorizontalScrollView) view.findViewById(R.id.hScroll);
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (childPosition == 0) {
gl1.removeAllViews();
}
int mMax = 8; // show 8 images
for (int i =0; i < mMax; i++) {
ImageView myImg = new ImageView(mContext);
myImg.setBackgroundRes(R.drawable.image1);
gl.addView(myImg);
}
return hScrl;
}
위와 관련된 문제가 있습니까? 더 많은 이미지가있는 경우 올바르게 표시되고 스크롤됩니다. 하지만 내 질문은 레이아웃을 팽창시키고 gl 및 hscrl을 가져 오는이 작업은 어댑터의 생성자 (위 그림 참조)에 있거나 getChildView에 있어야합니까?
이 4 LOC :
mInflater = LayoutInflater.from(mContext);
View view = infalInflater.inflate(R.layout.expandlist_items, null);
gl = (GridLayout) view.findViewById(R.id.gl);
hScrl = (HorizontalScrollView) view.findViewById(R.id.hScroll);