易采站长站为您分析android使用ExpandableListView控件实现小说目录效果的例子,还可以实现二级列表展示效果,需要的朋友可以参考下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF"
>
<ExpandableListView
android:id="@+id/elv_journal_catalog"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:cacheColorHint="#FFFFFF"
/>
</LinearLayout>
这代码很简单,和写listView的方法差不多,接下来是ExpandableListView在activity中的代码:
复制代码
private ExpandableListView elv_journal_catalog;
private List<List<Article>> childrenObj;
private JournalCatalogListAdapter adapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.journal_catalog);
init();
elv_journal_catalog.setGroupIndicator(null);
elv_journal_catalog.setDivider(null);
今天给大家讲讲android的目录实现方法,就像大家看到的小说目录一样,android 提供了ExpandableListView控件可以实现二级列表展示效果,现在给大家讲讲这个控件的用法,下面是XML定义:
复制代码<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF"
>
<ExpandableListView
android:id="@+id/elv_journal_catalog"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:cacheColorHint="#FFFFFF"
/>
</LinearLayout>
这代码很简单,和写listView的方法差不多,接下来是ExpandableListView在activity中的代码:
复制代码
private ExpandableListView elv_journal_catalog;
private List<List<Article>> childrenObj;
private JournalCatalogListAdapter adapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.journal_catalog);
init();
elv_journal_catalog.setGroupIndicator(null);
elv_journal_catalog.setDivider(null);
loadData();
}
private void init() {
elv_journal_catalog = (ExpandableListView) findViewById(R.id.elv_journal_catalog);
elv_journal_catalog.setOnChildClickListener(listener);
}
private void loadData() {
Message msg = handler.obtainMessage();










