0
我有一個ExpandableListView,它擴展了BaseExpandableListAdapter我想動態地添加ExpandableListView的孩子(當一個孩子點擊了其他佈局時) 請幫幫我。Android:ExpandableListView製作動態孩子
我有一個ExpandableListView,它擴展了BaseExpandableListAdapter我想動態地添加ExpandableListView的孩子(當一個孩子點擊了其他佈局時) 請幫幫我。Android:ExpandableListView製作動態孩子
寫適配器類等的下方的一個
public class ExpandableArtsListAdapter implements ExpandableListAdapter {
Context mContext;
LayoutInflater mLayoutInflator;
TopActivity top;
Arts[] list ;
public ImageLoader imageLoader;
private static List<All> newData;
public ExpandableArtsListAdapter(ToptActivity topActivity,
Arts[] lists) {
mContext = topActivity;
imageLoader = new ImageLoader(topActivity);
top =new TopActivity() ;
list = lists;
mLayoutInflator=LayoutInflater.from(mContext);
}
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return true;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return list[childPosition];
// TODO Auto-generated method stub
//return children[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder1 = new Holder();
if (convertView == null) {
convertView=mLayoutInflator.inflate(R.layout.top_child,null);
holder1.TopAll= (TextView)convertView.findViewById(R.id.top_text1);
holder1.Tops =(TextView)convertView.findViewById(R.id.top_text2);
holder1.AllGridView=(GridView)convertView.findViewById(R.id.top_gridview);
convertView.setTag(holder1);
}
else {
holder1 = (Holder) convertView.getTag();
}
holder1.TopAll.setText("Top");
final List<All> all= adapter.getList(arts.getId());
holder1.AllGridView.setAdapter(new TopGridViewAdapter(mContext,all));
holder1.Top.setText("Top ");
holder1.AllGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
}
}
});
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
// TODO Auto-generated method stub
//return children[groupPosition].length;
}
@Override
public long getCombinedChildId(long groupId, long childId) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getCombinedGroupId(long groupId) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return groupPosition;
// TODO Auto-generated method stub
//return groups[groupPosition];
}
@Override
public int getGroupCount() {
return list.length;
// TODO Auto-generated method stub
//return groups.length;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//write the appropriate code here
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void onGroupCollapsed(int groupPosition) {
// TODO Auto-generated method stub
}
@Override
public void onGroupExpanded(int groupPosition) {
// TODO Auto-generated method stub
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
class Holder {
public TextView TopAll;
public TextView Top;
public GridView AllGridView;
}
}