ExpandableListActivity

public class ExpList extends ExpandableListActivity
{
    static final String colors[] = {
   "grey",
   "blue",
   "yellow",
   "red"
 };

 static final String shades[][] = {
// Shades of grey
   {
  "lightgrey","#D3D3D3",
  "dimgray","#696969",
  "sgi gray 92","#EAEAEA"
   },
// Shades of blue
   {
  "dodgerblue 2","#1C86EE",
  "steelblue 2","#5CACEE",
  "powderblue","#B0E0E6"
   },
// Shades of yellow
   {
  "yellow 1","#FFFF00",
  "gold 1","#FFD700",
  "darkgoldenrod 1"," #FFB90F"
   },
// Shades of red
   {
  "indianred 1","#FF6A6A",
  "firebrick 1","#FF3030",
  "maroon","#800000"
   }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);
  SimpleExpandableListAdapter expListAdapter =
   new SimpleExpandableListAdapter(
    this,
    createGroupList(), // groupData describes the first-level entries
    R.layout.child_row, // Layout for the first-level entries
    new String[] { "colorName" }, // Key in the groupData maps to display
    new int[] { R.id.childname },  // Data under "colorName" key goes into this TextView
    createChildList(), // childData describes second-level entries
    R.layout.child_row, // Layout for second-level entries
    new String[] { "shadeName", "rgb" }, // Keys in childData maps to display
    new int[] { R.id.childname, R.id.rgb } // Data under the keys above go into these TextViews
   );
  setListAdapter( expListAdapter );
    }

/**
  * Creates the group list out of the colors[] array according to
  * the structure required by SimpleExpandableListAdapter. The resulting
  * List contains Maps. Each Map contains one entry with key "colorName" and
  * value of an entry in the colors[] array.
  */
 private List createGroupList() {
   ArrayList result = new ArrayList();
   for( int i = 0 ; i < colors.length ; ++i ) {
  HashMap m = new HashMap();
     m.put( "colorName",colors[i] );
  result.add( m );
   }
   return (List)result;
    }

/**
  * Creates the child list out of the shades[] array according to the
  * structure required by SimpleExpandableListAdapter. The resulting List
  * contains one list for each group. Each such second-level group contains
  * Maps. Each such Map contains two keys: "shadeName" is the name of the
  * shade and "rgb" is the RGB value for the shade.
  */
  private List createChildList() {
 ArrayList result = new ArrayList();
 for( int i = 0 ; i < shades.length ; ++i ) {
// Second-level lists
   ArrayList secList = new ArrayList();
   for( int n = 0 ; n < shades[i].length ; n += 2 ) {
     HashMap child = new HashMap();
  child.put( "shadeName", shades[i][n] );
     child.put( "rgb", shades[i][n+1] );
  secList.add( child );
   }
   result.add( secList );
 }
 return result;
  }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值