BaseExpandableListAdapter
extendsObject
implementsExpandableListAdapter
KnownDirectSubclasses
CursorTreeAdapter,SimpleExpandableListAdapter
KnownIndirectSubclasses
ResourceCursorTreeAdapter,SimpleCursorTreeAdapter
实例1:
importjava.util.ArrayList;
importandroid.app.ExpandableListActivity;
importandroid.content.Context;
importandroid.graphics.drawable.Drawable;
importandroid.os.Bundle;
importandroid.os.CountDownTimer;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseExpandableListAdapter;
importandroid.widget.ExpandableListAdapter;
importandroid.widget.ExpandableListView;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.ProgressBar;
importandroid.widget.TextView;
importandroid.widget.ExpandableListView.OnGroupClickListener;
importcom.sec.android.touchwiz.samples.R;
publicclassListLayoutSample12XmlextendsExpandableListActivity{
//Sampledataset.
privateStringmMailboxList[]={
"Inbox","Sentbox","Draft",
"Outbox","Emailinbox","Conversation",
"Trash","Myfolders"
};
privateStringmLoading="Loadingmessage...";
privateStringmSender[][]={{"Andrew1","Andrew2","Andrew3","Andrew4","Andrew5","Andrew6"},
{"Jeff1","Jeff2","Jeff3","Jeff4","Jeff5","Jeff6","Jeff7"},
{"ED1","ED2","ED3","ED4","ED5"},
{"Rachel1","Rachel2","Rachel3","Rachel4"},
{"Sean1","Sean2","Sean3","Sean4","Sean5"},
{"Karen1","Karen2","Karen3","Karen4","Karen5","Karen6","Karen7"},
{"Lisa1","Lisa2","Lisa3","Lisa4","Lisa5"},
{"Rain1","Rain2","Rain3","Rain4","Rain5"}};
privateStringmMailContext[][]={{"I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz..","?????","Callmeplz.."},
{"?????","Callmeplz..","?????","I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz.."},
{"?????","Callmeplz..","?????","Callmeplz..","?????"},
{"I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz.."},
{"?????","Callmeplz..","?????","Callmeplz..","?????"},
{"12312412","12414124","12412421","458645754","dfgsdgsdf","sdfgdfgh","sdfgdsfgh"},
{"vclkj","lkvoajh","alskdjfoivj","jvlkjasldkf","79837214"},
{"975432","kbvhuoisj","4362435,","342532","236dgasdt"}};
privateStringmDate[][]={{"11/22/09","11/23/08","09/11/07","02/03/05","00/09/09","11/11/11"},
{"12/12/12","12/25/09","01/03/09","11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"12/12/12","12/25/09","01/03/09","11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"}};
//childcount???loading...????group?child1??????????
//initvalueofchilddatacount,groupdatahave"Loadingmessag..."childdata,sotheinitvalueis1
privateintmChildCount[]={1,1,1,1,1,1,1,1};
ExpandableListViewmExpandableList;
ExpandableListAdaptermAdapter;
protectedArrayList<GroupItem>mGroupdata=newArrayList<GroupItem>();
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
mExpandableList=getExpandableListView();
//initializingExpandedmailboxlistdata
for(inti=0;i<mMailboxList.length;i++){
GroupItemitem=newGroupItem(i,mMailboxList <wbr style="line-height:25px">);<br style="line-height:25px"><br style="line-height:25px"> mGroupdata.add(item);<br style="line-height:25px"><br style="line-height:25px"> ChildItemitems=newChildItem(mLoading,null,null);<br style="line-height:25px"> item.mChilddata.add(items);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //Setupouradapter<br style="line-height:25px"> mAdapter=newExpandedMailboxListAdapter();<br style="line-height:25px"> setListAdapter(mAdapter);<br style="line-height:25px"> mExpandableList.setGroupIndicator(null);//Groupindicatordisable<br style="line-height:25px"><br style="line-height:25px"> mExpandableList.setOnGroupClickListener(newOnGroupClickListener(){<br style="line-height:25px"> publicbooleanonGroupClick(ExpandableListViewmExpandableList,Viewarg1,<br style="line-height:25px"> finalintgroupPosition,longid){<br style="line-height:25px"><br style="line-height:25px"> newCountDownTimer(3000,50){<br style="line-height:25px"> publicvoidonTick(longmillisUntilFinished){<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> publicvoidonFinish(){<br style="line-height:25px"> expandableListChange(groupPosition);<br style="line-height:25px"> }<br style="line-height:25px"> }.start();<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> });<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Expandablelist?childdata?set??childdata?set???method<br style="line-height:25px"> *SetChildlistdataofExpandablelist<br style="line-height:25px"> *Removefirstlistitemandreadditem<br style="line-height:25px"> *@paramgroupPosition<br style="line-height:25px"> */<br style="line-height:25px"> privatevoidexpandableListChange(intgroupPosition){<br style="line-height:25px"><br style="line-height:25px"> mGroupdata.get(groupPosition).mChilddata.remove(0);<br style="line-height:25px"> for(inti=0;i<mSender[groupPosition].length;i++){<br style="line-height:25px"> ChildItemitems=newChildItem(mSender[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">,mMailContext[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">,mDate[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">);<br style="line-height:25px"> mGroupdata.get(groupPosition).mChilddata.add(i,items);<br style="line-height:25px"> mChildCount[groupPosition]=mSender[groupPosition].length;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> ((BaseExpandableListAdapter)mAdapter).notifyDataSetChanged();<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *BaseExpandableListAdpater????expandablelistadpater??<br style="line-height:25px"> *DefineExpandableMailboxListAdpaterbyinheritBaseExpandableListAdpater<br style="line-height:25px"> */<br style="line-height:25px"> publicclassExpandedMailboxListAdapterextendsBaseExpandableListAdapter{<br style="line-height:25px"><br style="line-height:25px"> privateTextViewmMailbox;<br style="line-height:25px"> privateImageViewmMailboxIcon;<br style="line-height:25px"> privateTextViewmMailSender;<br style="line-height:25px"> privateTextViewmContext;<br style="line-height:25px"> privateTextViewmSubDate;<br style="line-height:25px"> privateProgressBarmProgress;<br style="line-height:25px"><br style="line-height:25px"> LinearLayoutmTodoView=null;<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *(non-Javadoc)<br style="line-height:25px"> *@seeandroid.widget.ExpandableListAdapter#getChild(int,int)<br style="line-height:25px"> */<br style="line-height:25px"> publicObjectgetChild(intarg0,intarg1){<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publiclonggetChildId(intgroupPosition,intchildPosition){<br style="line-height:25px"> returnchildPosition;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicintgetChildrenCount(intgroupPosition){<br style="line-height:25px"> returnmChildCount[groupPosition];<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Getchildviewandsetchilddata.<br style="line-height:25px"> *convertViewisreusedview<br style="line-height:25px"> */<br style="line-height:25px"> publicViewgetChildView(intgroupPosition,intchildPosition,booleanisLastChild,ViewconvertView,ViewGroupparent){<br style="line-height:25px"> //inti=0;<br style="line-height:25px"> if(convertView==null){<br style="line-height:25px"> LayoutInflatervi=null;<br style="line-height:25px"> vi=(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> mTodoView=(LinearLayout)vi.inflate(R.layout.listlayoutsample12xml_child,parent,false);<br style="line-height:25px"> }<br style="line-height:25px"> else{<br style="line-height:25px"> mTodoView=(LinearLayout)convertView;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> mProgress=(ProgressBar)mTodoView.findViewById(R.id.child_progressbar);<br style="line-height:25px"> mMailSender=(TextView)mTodoView.findViewById(R.id.child_text1);<br style="line-height:25px"> mContext=(TextView)mTodoView.findViewById(R.id.child_text2);<br style="line-height:25px"> mSubDate=(TextView)mTodoView.findViewById(R.id.child_text3);<br style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Visibility???Gone??set??????Visible?set??????Convetview???????<br style="line-height:25px"> *Gone????????????view??????.???GONE???????Visible???????<br style="line-height:25px"> *<br style="line-height:25px"> *IfusersetVisibilitytoGoneinspecificcase,userhavetosetVisibleinothercase.<br style="line-height:25px"> *BecauseConvertviewisreusedwithprefervisibilityattribute.<br style="line-height:25px"> */<br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender()==mLoading){<br style="line-height:25px"> mProgress.setVisibility(View.VISIBLE);<br style="line-height:25px"> mProgress.setIndeterminate(true);<br style="line-height:25px"> mMailSender.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender());<br style="line-height:25px"> }else{<br style="line-height:25px"> mProgress.setVisibility(View.GONE);<br style="line-height:25px"> mMailSender.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getContext()==null){<br style="line-height:25px"> mContext.setVisibility(View.GONE);<br style="line-height:25px"> }else{<br style="line-height:25px"> mContext.setVisibility(View.VISIBLE);<br style="line-height:25px"> mContext.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getContext());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getDate()==null){<br style="line-height:25px"> mSubDate.setVisibility(View.GONE);<br style="line-height:25px"> }else{<br style="line-height:25px"> mSubDate.setVisibility(View.VISIBLE);<br style="line-height:25px"> mSubDate.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getDate());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> returnmTodoView;<br style="line-height:25px"> }<br style="line-height:25px"> /*<br style="line-height:25px"> *(non-Javadoc)<br style="line-height:25px"> *@seeandroid.widget.ExpandableListAdapter#getGroup(int)<br style="line-height:25px"> */<br style="line-height:25px"> publicObjectgetGroup(intgroupPosition){<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicintgetGroupCount(){<br style="line-height:25px"> returnmMailboxList.length;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publiclonggetGroupId(intgroupPosition){<br style="line-height:25px"> returngroupPosition;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *GetGroupviewandsetgroupdata.<br style="line-height:25px"> *convertViewisreusedview<br style="line-height:25px"> */<br style="line-height:25px"> publicViewgetGroupView(intgroupPosition,booleanisExpanded,ViewconvertView,ViewGroupparent){<br style="line-height:25px"><br style="line-height:25px"> if(convertView==null){<br style="line-height:25px"> LayoutInflatervi=null;<br style="line-height:25px"> vi=(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> mTodoView=(LinearLayout)vi.inflate(R.layout.listlayoutsample12xml_group,parent,false);<br style="line-height:25px"> }<br style="line-height:25px"> else{<br style="line-height:25px"> mTodoView=(LinearLayout)convertView;<br style="line-height:25px"> }<br style="line-height:25px"> mMailboxIcon=(ImageView)mTodoView.findViewById(R.id.image1);<br style="line-height:25px"> mMailbox=(TextView)mTodoView.findViewById(R.id.text1);<br style="line-height:25px"><br style="line-height:25px"> mMailboxIcon.setImageDrawable(mGroupdata.get(groupPosition).getImage());<br style="line-height:25px"> mMailbox.setText(mGroupdata.get(groupPosition).getMailbox());<br style="line-height:25px"><br style="line-height:25px"> returnmTodoView;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //IndicateswhetherthechildandgroupIDsarestable<br style="line-height:25px"> publicbooleanhasStableIds(){<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //Whetherthechildatthespecifiedpositionisselectable.<br style="line-height:25px"> publicbooleanisChildSelectable(intgroupPosition,intchildPosition){<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *GroupItemclass<br style="line-height:25px"> *initGroupitemdatainlistlayoutsample12sml_group.xml<br style="line-height:25px"> *Groupitemhasownchilditem'sreference<br style="line-height:25px"> */<br style="line-height:25px"> privateclassGroupItem{<br style="line-height:25px"> privateStringmMailbox;<br style="line-height:25px"> privateDrawablemMailboxIcon;<br style="line-height:25px"> privateArrayList<ChildItem>mChilddata=newArrayList<ChildItem>();<br style="line-height:25px"><br style="line-height:25px"> publicGroupItem(inti,StringMailbox){<br style="line-height:25px"> mMailbox=Mailbox;<br style="line-height:25px"><br style="line-height:25px"> switch(i%4){<br style="line-height:25px"> case0:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image1);<br style="line-height:25px"> break;<br style="line-height:25px"> case1:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image2);<br style="line-height:25px"> break;<br style="line-height:25px"> case2:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image3);<br style="line-height:25px"> break;<br style="line-height:25px"> case3:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image4);<br style="line-height:25px"> break;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetMailbox(){<br style="line-height:25px"> returnmMailbox;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicDrawablegetImage(){<br style="line-height:25px"> returnmMailboxIcon;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *ChildItemclass<br style="line-height:25px"> *initchilditemdatainlistlayoutsample12sml_child.xml<br style="line-height:25px"> */<br style="line-height:25px"> privateclassChildItem{<br style="line-height:25px"> privateStringmSender;<br style="line-height:25px"> privateStringmContext;<br style="line-height:25px"> privateStringmDate;<br style="line-height:25px"><br style="line-height:25px"> publicChildItem(StringSender,StringContext,StringDate){<br style="line-height:25px"> mSender=Sender;<br style="line-height:25px"> mContext=Context;<br style="line-height:25px"> mDate=Date;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetSender(){<br style="line-height:25px"> returnmSender;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetContext(){<br style="line-height:25px"> returnmContext;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetDate(){<br style="line-height:25px"> returnmDate;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"></wbr></span></wbr></span></wbr></span></wbr>
extendsObject
implementsExpandableListAdapter
KnownDirectSubclasses
CursorTreeAdapter,SimpleExpandableListAdapter
KnownIndirectSubclasses
ResourceCursorTreeAdapter,SimpleCursorTreeAdapter
实例1:
importjava.util.ArrayList;
importandroid.app.ExpandableListActivity;
importandroid.content.Context;
importandroid.graphics.drawable.Drawable;
importandroid.os.Bundle;
importandroid.os.CountDownTimer;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseExpandableListAdapter;
importandroid.widget.ExpandableListAdapter;
importandroid.widget.ExpandableListView;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.ProgressBar;
importandroid.widget.TextView;
importandroid.widget.ExpandableListView.OnGroupClickListener;
importcom.sec.android.touchwiz.samples.R;
publicclassListLayoutSample12XmlextendsExpandableListActivity{
//Sampledataset.
privateStringmMailboxList[]={
"Inbox","Sentbox","Draft",
"Outbox","Emailinbox","Conversation",
"Trash","Myfolders"
};
privateStringmLoading="Loadingmessage...";
privateStringmSender[][]={{"Andrew1","Andrew2","Andrew3","Andrew4","Andrew5","Andrew6"},
{"Jeff1","Jeff2","Jeff3","Jeff4","Jeff5","Jeff6","Jeff7"},
{"ED1","ED2","ED3","ED4","ED5"},
{"Rachel1","Rachel2","Rachel3","Rachel4"},
{"Sean1","Sean2","Sean3","Sean4","Sean5"},
{"Karen1","Karen2","Karen3","Karen4","Karen5","Karen6","Karen7"},
{"Lisa1","Lisa2","Lisa3","Lisa4","Lisa5"},
{"Rain1","Rain2","Rain3","Rain4","Rain5"}};
privateStringmMailContext[][]={{"I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz..","?????","Callmeplz.."},
{"?????","Callmeplz..","?????","I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz.."},
{"?????","Callmeplz..","?????","Callmeplz..","?????"},
{"I'mgoingtogotowatchmovie!!!!!!!!!!!!!!!!!!!!!!!!!!","Hello....","Nicetomeetyou","Callmeplz.."},
{"?????","Callmeplz..","?????","Callmeplz..","?????"},
{"12312412","12414124","12412421","458645754","dfgsdgsdf","sdfgdfgh","sdfgdsfgh"},
{"vclkj","lkvoajh","alskdjfoivj","jvlkjasldkf","79837214"},
{"975432","kbvhuoisj","4362435,","342532","236dgasdt"}};
privateStringmDate[][]={{"11/22/09","11/23/08","09/11/07","02/03/05","00/09/09","11/11/11"},
{"12/12/12","12/25/09","01/03/09","11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"12/12/12","12/25/09","01/03/09","11/22/09","11/23/08","09/11/07","02/03/05"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"},
{"00/09/09","11/11/11","12/12/12","12/25/09","01/03/09"}};
//childcount???loading...????group?child1??????????
//initvalueofchilddatacount,groupdatahave"Loadingmessag..."childdata,sotheinitvalueis1
privateintmChildCount[]={1,1,1,1,1,1,1,1};
ExpandableListViewmExpandableList;
ExpandableListAdaptermAdapter;
protectedArrayList<GroupItem>mGroupdata=newArrayList<GroupItem>();
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
mExpandableList=getExpandableListView();
//initializingExpandedmailboxlistdata
for(inti=0;i<mMailboxList.length;i++){
GroupItemitem=newGroupItem(i,mMailboxList <wbr style="line-height:25px">);<br style="line-height:25px"><br style="line-height:25px"> mGroupdata.add(item);<br style="line-height:25px"><br style="line-height:25px"> ChildItemitems=newChildItem(mLoading,null,null);<br style="line-height:25px"> item.mChilddata.add(items);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //Setupouradapter<br style="line-height:25px"> mAdapter=newExpandedMailboxListAdapter();<br style="line-height:25px"> setListAdapter(mAdapter);<br style="line-height:25px"> mExpandableList.setGroupIndicator(null);//Groupindicatordisable<br style="line-height:25px"><br style="line-height:25px"> mExpandableList.setOnGroupClickListener(newOnGroupClickListener(){<br style="line-height:25px"> publicbooleanonGroupClick(ExpandableListViewmExpandableList,Viewarg1,<br style="line-height:25px"> finalintgroupPosition,longid){<br style="line-height:25px"><br style="line-height:25px"> newCountDownTimer(3000,50){<br style="line-height:25px"> publicvoidonTick(longmillisUntilFinished){<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> publicvoidonFinish(){<br style="line-height:25px"> expandableListChange(groupPosition);<br style="line-height:25px"> }<br style="line-height:25px"> }.start();<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> });<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Expandablelist?childdata?set??childdata?set???method<br style="line-height:25px"> *SetChildlistdataofExpandablelist<br style="line-height:25px"> *Removefirstlistitemandreadditem<br style="line-height:25px"> *@paramgroupPosition<br style="line-height:25px"> */<br style="line-height:25px"> privatevoidexpandableListChange(intgroupPosition){<br style="line-height:25px"><br style="line-height:25px"> mGroupdata.get(groupPosition).mChilddata.remove(0);<br style="line-height:25px"> for(inti=0;i<mSender[groupPosition].length;i++){<br style="line-height:25px"> ChildItemitems=newChildItem(mSender[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">,mMailContext[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">,mDate[groupPosition]<span style="line-height:25px"><wbr style="line-height:25px">);<br style="line-height:25px"> mGroupdata.get(groupPosition).mChilddata.add(i,items);<br style="line-height:25px"> mChildCount[groupPosition]=mSender[groupPosition].length;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> ((BaseExpandableListAdapter)mAdapter).notifyDataSetChanged();<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *BaseExpandableListAdpater????expandablelistadpater??<br style="line-height:25px"> *DefineExpandableMailboxListAdpaterbyinheritBaseExpandableListAdpater<br style="line-height:25px"> */<br style="line-height:25px"> publicclassExpandedMailboxListAdapterextendsBaseExpandableListAdapter{<br style="line-height:25px"><br style="line-height:25px"> privateTextViewmMailbox;<br style="line-height:25px"> privateImageViewmMailboxIcon;<br style="line-height:25px"> privateTextViewmMailSender;<br style="line-height:25px"> privateTextViewmContext;<br style="line-height:25px"> privateTextViewmSubDate;<br style="line-height:25px"> privateProgressBarmProgress;<br style="line-height:25px"><br style="line-height:25px"> LinearLayoutmTodoView=null;<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *(non-Javadoc)<br style="line-height:25px"> *@seeandroid.widget.ExpandableListAdapter#getChild(int,int)<br style="line-height:25px"> */<br style="line-height:25px"> publicObjectgetChild(intarg0,intarg1){<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publiclonggetChildId(intgroupPosition,intchildPosition){<br style="line-height:25px"> returnchildPosition;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicintgetChildrenCount(intgroupPosition){<br style="line-height:25px"> returnmChildCount[groupPosition];<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Getchildviewandsetchilddata.<br style="line-height:25px"> *convertViewisreusedview<br style="line-height:25px"> */<br style="line-height:25px"> publicViewgetChildView(intgroupPosition,intchildPosition,booleanisLastChild,ViewconvertView,ViewGroupparent){<br style="line-height:25px"> //inti=0;<br style="line-height:25px"> if(convertView==null){<br style="line-height:25px"> LayoutInflatervi=null;<br style="line-height:25px"> vi=(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> mTodoView=(LinearLayout)vi.inflate(R.layout.listlayoutsample12xml_child,parent,false);<br style="line-height:25px"> }<br style="line-height:25px"> else{<br style="line-height:25px"> mTodoView=(LinearLayout)convertView;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> mProgress=(ProgressBar)mTodoView.findViewById(R.id.child_progressbar);<br style="line-height:25px"> mMailSender=(TextView)mTodoView.findViewById(R.id.child_text1);<br style="line-height:25px"> mContext=(TextView)mTodoView.findViewById(R.id.child_text2);<br style="line-height:25px"> mSubDate=(TextView)mTodoView.findViewById(R.id.child_text3);<br style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *Visibility???Gone??set??????Visible?set??????Convetview???????<br style="line-height:25px"> *Gone????????????view??????.???GONE???????Visible???????<br style="line-height:25px"> *<br style="line-height:25px"> *IfusersetVisibilitytoGoneinspecificcase,userhavetosetVisibleinothercase.<br style="line-height:25px"> *BecauseConvertviewisreusedwithprefervisibilityattribute.<br style="line-height:25px"> */<br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender()==mLoading){<br style="line-height:25px"> mProgress.setVisibility(View.VISIBLE);<br style="line-height:25px"> mProgress.setIndeterminate(true);<br style="line-height:25px"> mMailSender.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender());<br style="line-height:25px"> }else{<br style="line-height:25px"> mProgress.setVisibility(View.GONE);<br style="line-height:25px"> mMailSender.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getSender());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getContext()==null){<br style="line-height:25px"> mContext.setVisibility(View.GONE);<br style="line-height:25px"> }else{<br style="line-height:25px"> mContext.setVisibility(View.VISIBLE);<br style="line-height:25px"> mContext.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getContext());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getDate()==null){<br style="line-height:25px"> mSubDate.setVisibility(View.GONE);<br style="line-height:25px"> }else{<br style="line-height:25px"> mSubDate.setVisibility(View.VISIBLE);<br style="line-height:25px"> mSubDate.setText(mGroupdata.get(groupPosition).mChilddata.get(childPosition).getDate());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> returnmTodoView;<br style="line-height:25px"> }<br style="line-height:25px"> /*<br style="line-height:25px"> *(non-Javadoc)<br style="line-height:25px"> *@seeandroid.widget.ExpandableListAdapter#getGroup(int)<br style="line-height:25px"> */<br style="line-height:25px"> publicObjectgetGroup(intgroupPosition){<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicintgetGroupCount(){<br style="line-height:25px"> returnmMailboxList.length;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publiclonggetGroupId(intgroupPosition){<br style="line-height:25px"> returngroupPosition;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *GetGroupviewandsetgroupdata.<br style="line-height:25px"> *convertViewisreusedview<br style="line-height:25px"> */<br style="line-height:25px"> publicViewgetGroupView(intgroupPosition,booleanisExpanded,ViewconvertView,ViewGroupparent){<br style="line-height:25px"><br style="line-height:25px"> if(convertView==null){<br style="line-height:25px"> LayoutInflatervi=null;<br style="line-height:25px"> vi=(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> mTodoView=(LinearLayout)vi.inflate(R.layout.listlayoutsample12xml_group,parent,false);<br style="line-height:25px"> }<br style="line-height:25px"> else{<br style="line-height:25px"> mTodoView=(LinearLayout)convertView;<br style="line-height:25px"> }<br style="line-height:25px"> mMailboxIcon=(ImageView)mTodoView.findViewById(R.id.image1);<br style="line-height:25px"> mMailbox=(TextView)mTodoView.findViewById(R.id.text1);<br style="line-height:25px"><br style="line-height:25px"> mMailboxIcon.setImageDrawable(mGroupdata.get(groupPosition).getImage());<br style="line-height:25px"> mMailbox.setText(mGroupdata.get(groupPosition).getMailbox());<br style="line-height:25px"><br style="line-height:25px"> returnmTodoView;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //IndicateswhetherthechildandgroupIDsarestable<br style="line-height:25px"> publicbooleanhasStableIds(){<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //Whetherthechildatthespecifiedpositionisselectable.<br style="line-height:25px"> publicbooleanisChildSelectable(intgroupPosition,intchildPosition){<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *GroupItemclass<br style="line-height:25px"> *initGroupitemdatainlistlayoutsample12sml_group.xml<br style="line-height:25px"> *Groupitemhasownchilditem'sreference<br style="line-height:25px"> */<br style="line-height:25px"> privateclassGroupItem{<br style="line-height:25px"> privateStringmMailbox;<br style="line-height:25px"> privateDrawablemMailboxIcon;<br style="line-height:25px"> privateArrayList<ChildItem>mChilddata=newArrayList<ChildItem>();<br style="line-height:25px"><br style="line-height:25px"> publicGroupItem(inti,StringMailbox){<br style="line-height:25px"> mMailbox=Mailbox;<br style="line-height:25px"><br style="line-height:25px"> switch(i%4){<br style="line-height:25px"> case0:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image1);<br style="line-height:25px"> break;<br style="line-height:25px"> case1:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image2);<br style="line-height:25px"> break;<br style="line-height:25px"> case2:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image3);<br style="line-height:25px"> break;<br style="line-height:25px"> case3:<br style="line-height:25px"> mMailboxIcon=getResources().getDrawable(R.drawable.listlayoutsample12xml_image4);<br style="line-height:25px"> break;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetMailbox(){<br style="line-height:25px"> returnmMailbox;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicDrawablegetImage(){<br style="line-height:25px"> returnmMailboxIcon;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *ChildItemclass<br style="line-height:25px"> *initchilditemdatainlistlayoutsample12sml_child.xml<br style="line-height:25px"> */<br style="line-height:25px"> privateclassChildItem{<br style="line-height:25px"> privateStringmSender;<br style="line-height:25px"> privateStringmContext;<br style="line-height:25px"> privateStringmDate;<br style="line-height:25px"><br style="line-height:25px"> publicChildItem(StringSender,StringContext,StringDate){<br style="line-height:25px"> mSender=Sender;<br style="line-height:25px"> mContext=Context;<br style="line-height:25px"> mDate=Date;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetSender(){<br style="line-height:25px"> returnmSender;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetContext(){<br style="line-height:25px"> returnmContext;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetDate(){<br style="line-height:25px"> returnmDate;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"></wbr></span></wbr></span></wbr></span></wbr>