import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.ArrayList;
import java.util.List;
public class Test extends Fragment {
View view;
private ExpandableListView expList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.activity_birlynn, null);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ExpAdapter EAT = new ExpAdapter(getActivity());
ArrayList<String> title = new ArrayList<String>();
for(int i = 0;i<3;i++)
title.add(String.valueOf(i));
ArrayList<ArrayList<ChildrenItemModel>> ACM = new ArrayList<ArrayList<ChildrenItemModel>>();
ChildrenItemModel CM = new ChildrenItemModel();
CM.setImgUrl("drawable://"+R.drawable.zhangjie);
CM.setMyMood("好心情");
CM.setName("Edward");
CM.setStatus("[APP 在线]");
ChildrenItemModel TM = new ChildrenItemModel();
TM.setImgUrl("drawable://"+R.drawable.cctv);
TM.setMyMood("坏心情");
TM.setName("Kent");
TM.setStatus("[APP 在线]");
ArrayList<ChildrenItemModel> ac = new ArrayList<ChildrenItemModel>();
ArrayList<ChildrenItemModel> bc = new ArrayList<ChildrenItemModel>();
ac.add(CM);
bc.add(TM);
ACM.add(ac);
ACM.add(bc);
EAT.setGoupandChildrenList(title,ACM);
expList = (ExpandableListView) getActivity().findViewById(R.id.MyFriends);
expList.setAdapter(EAT);
}
class ExpAdapter extends BaseExpandableListAdapter{
private LayoutInflater layoutInflater;
private List<String> groupList;
private ArrayList<ArrayList<ChildrenItemModel>> childrenList;
public void setGoupandChildrenList(List<String> groupList, ArrayList<ArrayList<ChildrenItemModel>> childrenList){
this.childrenList = childrenList;
this.groupList = groupList;
}
public ExpAdapter(Context context){
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getGroupCount() {
return groupList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return childrenList.size();
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupViewHolder groupViewHolder = null;
if(convertView==null){
groupViewHolder = new GroupViewHolder();
convertView = layoutInflater.inflate(R.layout.parentepxlist_layout,null);
groupViewHolder.groupTitle = (TextView) convertView.findViewById(R.id.gourpName);
convertView.setTag(groupViewHolder);
}else{
groupViewHolder = (GroupViewHolder)convertView.getTag();
}
groupViewHolder.groupTitle.setText(groupList.get(groupPosition));
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildrenViewHolder childrenViewHolder = null;
if(convertView==null){
convertView = layoutInflater.inflate(R.layout.children_layout,null);
childrenViewHolder = new ChildrenViewHolder();
childrenViewHolder.setImgUrl((ImageView) convertView.findViewById(R.id.childrenPic));
childrenViewHolder.setMyMood((TextView) convertView.findViewById(R.id.myMood));
childrenViewHolder.setStatus((TextView) convertView.findViewById(R.id.childrenStatus));
childrenViewHolder.setName((TextView) convertView.findViewById(R.id.childrenName));
convertView.setTag(childrenViewHolder);
}else{
childrenViewHolder = (ChildrenViewHolder) convertView.getTag();
}
childrenViewHolder.getName().setText(childrenList.get(groupPosition).get(childPosition).getName());
childrenViewHolder.getMyMood().setText(childrenList.get(groupPosition).get(childPosition).getMyMood());
childrenViewHolder.getStatus().setText(childrenList.get(groupPosition).get(childPosition).getStatus());
ImageLoader.getInstance().displayImage(childrenList.get(groupPosition).get(childPosition).getImgUrl(),childrenViewHolder.getImgUrl());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
class GroupViewHolder{
TextView groupTitle;
}
class ChildrenViewHolder{
private ImageView imgUrl;
private TextView name;
private TextView status;
private TextView myMood;
public TextView getMyMood() {
return myMood;
}
public TextView getName() {
return name;
}
public TextView getStatus() {
return status;
}
public void setName(TextView name) {
this.name = name;
}
public void setMyMood(TextView myMood) {
this.myMood = myMood;
}
public void setStatus(TextView status) {
this.status = status;
}
public ImageView getImgUrl() {
return imgUrl;
}
public void setImgUrl(ImageView imgUrl) {
this.imgUrl = imgUrl;
}
}
}
}
fatewa
相关分类