android--------ExpandableListView的使用多级列表


多级列表ExpandableListView

扩展列表能够显示一个指示在每项显示项的当前状态(状态通常是一个扩展的组,组的孩子,或倒塌,最后一个孩子)。使用setchildindicator(drawable)或setgroupindicator(drawable)(或相应的XML属性)来设置这些指标,一个默认的风格多级列表提供指标,将示给意见多级列表。布局android.r.layout.simple_expandable_list_item_1和android.r.layout.simple_expandable_list_item_2(应用simplecursortreeadapter)包含位置信息的首选指标。

效果图:


android--------ExpandableListView的使用多级列表_第1张图片



public class MainActivity extends Activity {
	private ExpandableListView listView;
	private List group;
	private List> child;
	private MyAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		listView = (ExpandableListView) findViewById(R.id.expandableListView);
		/**
		 * 初始化数据 
		 */
		initData();
		adapter = new MyAdapter(this,group,child);
		listView.setAdapter(adapter);
	
	}
	
	
	

	private void initData() {
		group = new ArrayList();
		child = new ArrayList>();
		addInfo("笑傲江湖",new String[]{"东方不败","风清扬","令狐冲","岳不群"});
		addInfo("天龙八部", new String[]{"乔峰","虚竹","段誉"});
		addInfo("九阴真经", new String[]{"中神通","东邪","西毒","南帝","北丐"});
	}
	
	/**
	 * 添加数据信息
	 * @param g
	 * @param c
	 */
	private void addInfo(String g,String[] c) {
		group.add(g);
		List list = new ArrayList();
		for (int i = 0; i < c.length; i++) {
			list.add(c[i]);
		}
		child.add(list);
	}

}

源代码下载





你可能感兴趣的:(Android)