Fragment中如何获取listview

============问题描述============


    我的FileFragment继承了Fragment,现在我想要在FileFragment中获取获取file.xml中的一个listview,我用了下面两种方式:
       //fileListView=(ListView)getActivity().findViewById(R.id.file_list);得到空指针
fileListView=(ListView)inflater.inflate(R.id.file_list, null);找不到资源

    请指教在Fragment中如何获取listview。

============解决方案1============


View rootView = inflater.inflate(R.layout.file, null); //先解析file.xml布局,得到一个view

ListView listView = (ListView) rootView.findViewById(R.id.file_list);

posted on 2014-10-24 09:13  android基础教程  阅读(596)  评论(0编辑  收藏  举报

导航

我要啦免费统计