import java.util.ArrayList;
import java.util.HashMap;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
public class sedactivity extends ExpandableListActivity { ExpandableListAdapter mAdapter;
private final static String NAME = "NAME";
private final static String SURNAME = "SURNAME";
private Drawable photo, photo2, photo3, photo4;
private List<Drawable> albumCovers;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_main);
res = this.getResources();
photo = (Drawable) res.getDrawable(R.drawable.bosco);
photo2 = (Drawable) res.getDrawable(R.drawable.albero);
photo3 = (Drawable) res.getDrawable(R.drawable.bomba);
photo4 = (Drawable) res.getDrawable(R.drawable.astronave);
albumCovers = new ArrayList<Drawable>();
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "A");
curGroupMap.put(SURNAME, "(2 Foto)");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Albero");
curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Astronave");
curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "B");
curGroupMap.put(SURNAME, "(2 Foto)");
children = new ArrayList<Map<String, String>>();
curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Bosco");
curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Bomba");
curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "C");
curGroupMap.put(SURNAME, "(0 Foto)");
children = new ArrayList<Map<String, String>>();
mAdapter = new MyExpandableListAdapter(
new String[] { NAME, SURNAME },
new int[] { R.id.rowText1, R.id.rowText2, R.id.photoAlbumImg },
new String[] { NAME, SURNAME },
new int[] { R.id.rowText1, R.id.photoAlbumImg }
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
public class MyExpandableListAdapter extends SimpleExpandableListAdapter {
private List<? extends List<? extends Map<String, ?>>> mChildData;
private String[] mChildFrom;
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);
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
v = newChildView(isLastChild, parent);
bindView(v, mChildData.get(groupPosition).get(childPosition), mChildFrom,
mChildTo, groupPosition, childPosition);
private void bindView(View view, Map<String, ?> data, String[] from, int[] to, int groupPosition, int childPosition) {
for (int i = 0; i < len; ++i) {
TextView v = (TextView) view.findViewById(to[i]);
v.setText((String) data.get(from[i]));
ImageView imgV = (ImageView) view.findViewById(to[1]);
if(childPosition % 1 == 0) imgV.setImageDrawable(albumCovers.get(0));
else imgV.setImageDrawable(albumCovers.get(1));