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);
时间: 2024-08-01 22:33:42

Fragment中如何获取listview的相关文章

在Fragment中加一个嵌套了ListView的ScrollView(一)

首先介绍一下这个程序的功能: 1.顶部有两个可以切换Fragment的Button 2.在其中一个Fragment中里有个ScrollView,ScrollView中有ViewFlipper,ListView.(另一个Fragment中就随意了) 随着listView的滚动,ViewFlipper中的内容也会滚动. 3.两个布局(主布局,一个Fragment的布局(另一个没写,其实都一样)),一个Fragment,一个主Activity,重写ListView(不重写的话,不会随着ViewFlip

Windows Phone 8.1开发:如何从ListView中,获取ScrollViewer对象

在使用ListView作为信心呈现载体开发应用程序时,我们经常需要通过监视滚动条(ScrollViewer)的位置状态来完成一些交互逻辑.最直接的体现就是 延时加载,(上滑加载更多,下拉获取更新数据). 我们可以通过 scrollViewer的ViewChanged事件,来完成这些逻辑. 那么问题来了.(- -!不是说挖掘机--..) 如何从ListView中,获取ScrollViewer对象? 1.我们可以通过这样一个方法来 获取ListView下的ScrollViewer对象.  方法定义如

Fragment中获取Activity的Context (转)

Fragment中获取Activity的Context时只需要this.getActivity()即可.     而不是许多人说的this.getActivity().getApplicationContext(),如果用后者传入AlterDialog肯定会报错(android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application).    因为只有ac

如何在Fragment中获取context

文章转载自http://blog.csdn.net/demonliuhui/article/details/51511136 这里仅供自己学习参考: Context,中文直译为"上下文",SDK中对其说明如下: 1.它描述的是一个应用程序环境的信息,即上下文. 2.该类是一个抽象(abstract class)类,Android提供了该抽象类的具体实现类(后面我们会讲到是ContextIml类). 3.通过它我们可以获取应用程序的资源和类,也包括一些应用级别操作,例如:启动一个Acti

C# 获取ListView中选中行中对应的列数据

C# 获取ListView中选中行中对应的列数据 if (MediaList.SelectedIndices != null && MediaList.SelectedIndices.Count > 0) { ListView.SelectedIndexCollection c = MediaList.SelectedIndices; string mediaRtspUrl = MediaList.Items[c[0]].SubItems[2].Text.ToString(); }

向 ViewPager 中添加 包含 ListView 的 Fragment

对与fragment就不说什么了,直接看API手册吧,亲. 向 ViewPager 中添加 包含 ListView 的 Fragment 的过程比较麻烦.他所表现的效果就是新闻客户端的滑动翻页效果. 在这里就不粘代码了.只把思路理一下.代码有时间再粘: 一,你需要一个 ViewPager :在实验时,我的activity中就只有一个ViewPager.没有别的东西. 二,你需要一个自定义的fragment,在我们这里的话,这种fragment中有一个listView就可以了(布局文件中只有一个L

android,在fragment中使用listview,不使用listfragment

public class LeftFragment extends Fragment{ private ListView listView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.lesson_table_left, null); listV

Fragment中获取Activity的Context

Fragment中获取Activity的Context时只需要this.getActivity()即可.    而不是许多人说的this.getActivity().getApplicationContext(),如果用后者传入AlterDialog肯定会报错(android.view.WindowManager$BadTokenException: Unable to addwindow -- token null is not for an application).   因为只有activ

如何在Fragment中获取FragmentActivity中的布局????

============问题描述============ 我是想在Fragment中往FragmentActivity里面的布局里添加控件,现在我怎么在Fragment中得到这个布局呢?? ============解决方案1============ 一种思路是定义一个接口,如 OnDecoratorSelectListener,然后Activity实现这个接口,当Fragment里面选择了一个脸型的时候,调用((OnDecoratorSelectListener)getActivity).onD