开发者

Can an ExpandableListView be embedded in another layout?

I would like to have an expandable/collap开发者_Go百科sible listview in my app, similar to how the comments are displayed for each app in the Market (in fact, each item in the list is a comment on the same format as in the Market). As there can be many list items and I don't want the user to lose the buttons that are below the list, and the user may not be interested to read the items in the list, I would like this list to be expandable and collapsible.

I've looked at extending BaseExpandableListAdapter and it seems really neat, except for the fact that it seems that the list is always displayed using an ExpandableListActivity. I would like the list embedded in the page the user is already looking at.

Does anyone know if this is possible using BaseExpandableListAdapter or if I have to use a different technique altogether and write all the boilerplate code myself?

Many thanks, Nina


Yes, it is not difficult to use ListView, ExpandableListView and friends without their associated activities.

You just need to call setAdapter() on your ExpandableListView after instantiating it or retrieving it from your layout:

ExpandableListView list = (ExpandableListView) findViewById(R.id.listView);
list.setAdapter(myExpandableAdapter);


Sure. There should be no problem. An ExpandableListActivity is just a thin veneer over an ExpandableListView (actually, any layout that has an ExpandableListView with an id of android.R.id.list. You can either use an ExpandableListActivity with your own custom layout or else define your own activity and give up the (relatively few) convenience methods that ExpandableListActivity provides.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜