expandablelistview片段与主/详细流程 [英] expandablelistview in fragment with master/detail flow

查看:114
本文介绍了expandablelistview片段与主/详细流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建在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:


  1. 片段而不是 ListFragment
  2. 扩展
  3. 创建,你宣布一个XML布局文件的 ExpandableListView

  4. 覆盖 onCreateView()和膨胀包含布局 ExpandableListView

  5. 得到一个参考 ExpandableListView ,然后用它像之前。

  1. Extend from Fragment, instead of ListFragment
  2. Create an xml layout file where you declare an ExpandableListView
  3. Override onCreateView() and inflate the layout that contains the ExpandableListView
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆