ITEEDU

SimpleExpandableListAdapter示例

public class ExpandableListSample4Xml extends ExpandableListActivity {
	private int mGroupIdColumnIndex;
	// Sample data set.
	private String mMailboxList[]={
		"Inbox", "Sentbox", "Draft",
		"Outbox", "Email inbox", "Conversation",
		"Trash", "My folders"
	};
	private String mSender[][] = { 
		{"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"}};
		private String mMailContext[][] = { 
			{"I'm going to go to watch movie!!!!!!!!!!!!!!!!!!!!!!!!!!", 
				"Hello....", "Nice to meet you", "Call me plz..",
				"Are you busy",  "Call me plz.." },
			{"hi" , "Call me plz.." , "hello", 
				"I'm going to go to watch movie!!!!!!!!!!!!!!!!!!!!!!!!!!", 
				"Hello....", "Nice to meet you", "Call me plz.."},
			{"hi,baby",  "Call me plz.." , "hi" , "Call me plz.." , "hello"},
			{"I'm going to go to watch movie!!!!!!!!!!!!!!!!!!!!!!!!!!", 
				"Hello....", "Nice to meet you", "Call me plz.."},
			{"hi",  "Call me plz.." , "hi" , "Call me plz.." , "?????"},
			{"12312412","12414124","12412421",
				"458645754","dfgsdgsdf","sdfgdfgh","sdfgdsfgh"},
			{"vclkj","lkvoajh","alskdjfoivj","jvlkjasldkf","79837214"},
		{"975432","kbvhuoisj","4362435,","342532","236dgasdt"}};

			private String groupFrom[] = {"title"};
			private int groupTo[] = {android.R.id.text1};

			private String childFrom[] = {"name", "message"};
			private int childTo[] = {R.id.child_name, R.id.child_message};
			private ExpandableListAdapter mAdapter;
			private ArrayList<Map<String, String>> groupData =
				new ArrayList<Map<String, String>>();
			private ArrayList<ArrayList<Map<String, String>>> childData =
				new ArrayList<ArrayList<Map<String, String>>>();
			@Override
			public void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				// Query for people
				Cursor groupCursor = managedQuery(Phone.CONTENT_URI,
					new String[] {Phone._ID, Phone.DISPLAY_NAME}, null, null, null);
				// Cache the ID column index
				mGroupIdColumnIndex = groupCursor.getColumnIndexOrThrow(Phone._ID);
				// make data for group & child
				for(int i = 0; i < mMailboxList.length; i++) {
					HashMap<String, String> tempGroupData = new HashMap<String, String>();
					ArrayList<Map<String, String>> tmpChild = new ArrayList<Map<String, String>>();
					tempGroupData.put(groupFrom[0], mMailboxList);
					for(int j = 0; j < mSender.length; j++) {
						HashMap<String, String> tempChildData = new HashMap<String, String>();
						tempChildData.put(childFrom[0], mSender[j]);
						tempChildData.put(childFrom[1], mMailContext[j]);

						tmpChild.add(tempChildData);
					}
					groupData.add(tempGroupData);
					childData.add(tmpChild);
				}
				// Set up our adapter
				mAdapter = new MyExpandableListAdapter(this,
				groupData,
				android.R.layout.simple_expandable_list_item_1,
				groupFrom,
				groupTo,
				childData,
				R.layout.expandablelistsample4xml_child,
				childFrom,
				childTo);
				setListAdapter(mAdapter);
			}
			public class MyExpandableListAdapter extends SimpleExpandableListAdapter {
				public MyExpandableListAdapter(Context context,
				List<? extends Map<String, ?>> groupData,
				int groupLayout,
				String[] groupFrom,
				int[] groupTo,
				List<? extends List<? extends Map<String, ?>>> childData,
				int childLayout,
				String[] childFrom,
				int[] childTo) {
					super(context, groupData, groupLayout, groupFrom, groupTo, childData,
					childLayout, childFrom, childTo);
				}
			}
		}