WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院手机开发Android 开发 详解android 可展开(收缩)的列表ListView(Expan... 阅读

详解android 可展开(收缩)的列表ListView(ExpandableListView)

 2010-05-11 16:15:00 来源:WEB开发网 闂侀潧妫撮幏锟�闂佸憡鍨电换鎰版儍椤掑倵鍋撳☉娆嶄沪缂傚稄鎷�婵犫拃鍛粶闁靛洤娲ㄩ埀顒佺⊕閵囩偟绱為敓锟�闂侀潧妫撮幏锟�  闂佺ǹ绻楀▍鏇㈠极閻愬灚瀚梺鍨儏閳ь剙绉归弻銊р偓闈涙啞閻h京鈧敻鍋婇崰鏍х暦閿燂拷
核心提示:每天都在用QQ聊天,今天突然一想,详解android 可展开(收缩)的列表ListView(ExpandableListView),android怎么实现列表的分组展开呢?看了看api,发现其实现过程也很简单,继承android.widget.BaseExpandableListAdapter,package com.

每天都在用QQ聊天,今天突然一想,android怎么实现列表的分组展开呢?看了看api,发现其实现过程也很简单。先看一下最终效果吧!

1、首先创建我们的Activity,继承 android.app.ExpandableListActivity,直接看代码吧。

package com.ideasandroid.sample;

import android.app.ExpandableListActivity;

import android.os.Bundle;

import com.ideasandroid.sample.adapter.IdeasExpandableListAdapter;

/**

* @author IdeasAndroid

* 可展开(收缩)列表示例

*/

public class IdeasExpandableListView extends ExpandableListActivity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//设置列表适配器IdeasExpandableListAdapter

setListAdapter(new IdeasExpandableListAdapter(this));

}

}

2、创建适配器,继承android.widget.BaseExpandableListAdapter。

package com.ideasandroid.sample.adapter;

import java.util.ArrayList;

import java.util.List;

import android.content.Context;

import android.view.Gravity;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AbsListView;

import android.widget.BaseExpandableListAdapter;

import android.widget.TextView;

/**

* @author IdeasAndroid

* 可展开(收缩)列表示例

*/

public class IdeasExpandableListAdapter extends BaseExpandableListAdapter {

private Context mContext = null;

// 测试数据,开发时可能来自数据库,网络....

private String[] groups = { "家人", "朋友", "同事" };

private String[] familis = { "老爸", "老妈", "妹妹" };

private String[] friends = { "小李", "张三", "李四" };

private String[] colleagues = { "陈总", "李工", "李客户" };

private List<String> groupList = null;

1 2 3 4  下一页

Tags:详解 android 展开

编辑录入:coldstar [复制链接] [打 印]
赞助商链接