expandablelistview片段与主/详细流程 [英] expandablelistview in fragment with master/detail flow
问题描述
我想创建在Android 4.2的主/从流量应用。
I am trying to create a master/detail flow application on Android 4.2.
我创建了一个主从流量工程,但我想实现一个的 ExpandableListView
不是的ListView
的提供。
I have created a master detail flow project, but I want to implement an ExpandableListView
instead of the ListView
that is provided.
在主/从使用的片段,这里是我在哪里卡住了......我已经成功地创建一个单独的项目可扩展列表视图。我如何能主/从里面流实现它?
The master/detail uses fragments, and here’s where I am stuck… I have successfully created an expandable list view in a separate project. How can I implement it inside a master/detail flow?
推荐答案
我假设你使用IDE向导来创建主/详细示例项目。如果是这样,那么你可能看到向导创建一个 ItemListFragment
类,默认扩展 ListFragment
。
I assume you used the IDE wizard to create the Master/Detail example project. If this is so, then you probably saw that the wizard created an ItemListFragment
class which by default extends ListFragment
.
如果你需要一个可扩展的一个替代简单的列表,那么你就必须为:
If you need to replace the simple list with an expandable one, then you'll have to:
- 从
片段
而不是ListFragment
, 扩展 - 创建,你宣布一个XML布局文件的
ExpandableListView
- 覆盖
onCreateView()
和膨胀包含布局ExpandableListView
- 得到一个参考
ExpandableListView
,然后用它像之前。
- Extend from
Fragment
, instead ofListFragment
- Create an xml layout file where you declare an
ExpandableListView
- Override
onCreateView()
and inflate the layout that contains theExpandableListView
- Get a reference to the
ExpandableListView
, and then use it as you did before.
事情是这样的:
// extend from Fragment
public class ItemListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// inflate the layout that contains the ExpandableListView
View view = inflater.inflate(R.layout.fragment_items_list, container, false);
// get a reference to ExpandableListView
ExpandableListView list = (ExpandableListView)view.findViewById(R.id.my_list);
// set the adapter
// set listeners
return view;
}
}
这篇关于expandablelistview片段与主/详细流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!