Fragment用findViewById得到空值解决办法
来源:互联网 发布:mac怎样新建文件夹 编辑:程序博客网 时间:2024/06/06 00:40
参考:http://www.cnblogs.com/Ken-Cai/p/4186660.html
public class CompanyListFragment extends Fragment { private Activity activity; private ListView companyListView; @Override public View onCreateView(LayoutInflater infalter, ViewGroup container, Bundle savedInstanceState) { View view = infalter.inflate(R.layout.companylist_for_sport, container, false); companyListView = (ListView)view.findViewById(R.id.companyListView); return view; }}
注意1: 是在 onCreateView 中
注意2: 是 view.findViewById 而不是 activity.findViewById
为了能在别的方法中调用,最好写成:
public class CompanyListFragment extends Fragment { private Activity activity; private ListView companyListView; private View view; @Override public View onCreateView(LayoutInflater infalter, ViewGroup container, Bundle savedInstanceState) { view = infalter.inflate(R.layout.companylist_for_sport, container, false); companyListView = (ListView)view.findViewById(R.id.companyListView); return view; } public void mothedA(){ ListView = (ListView)view.findViewById(R.id.companyListView); }}
0 0
- Fragment用findViewById得到空值解决办法
- Android fragment 获取id,findViewById为空
- findViewById 返回值为空
- 自定义控件findViewById得到空指针,错误的排除
- 自定义控件findViewById得到空指针,错误的排除
- 空指针异常 anko for Android findviewbyId fragment ondestoryView
- Android使用Fragment,不能得到Fragment内部控件,findViewById()结果是Null--已经解决
- findviewbyid()值为空的问题
- 得到一个空值
- Fragment中的findviewbyid
- findViewById为空
- findViewById空指针
- 在Fragment中加载布局后使用findViewById出现空指针错误
- 使用findViewById获取到的返回值为空
- 在 fragment 里面调用 findViewById
- 在 fragment 里面调用 findViewById
- 在 fragment 里面调用 findViewById
- android findviewByid()关于空指针
- 新标准c++程序设计教程chapter2_2015.7.28
- shell下在while循环中使用ssh命令的问题
- xargs 命令
- easyui的datebox限定范围
- 关于运算符重载
- Fragment用findViewById得到空值解决办法
- 课程设计记实(航空订票系统)——第二篇
- 09_EGIT插件的安装,Eclipse中克隆(clone),commit,push,pull操作演示
- 欢迎使用CSDN-markdown编辑器
- Ubuntu 下 python 安装 MySQLdb
- 酷融贷官网
- IOS读取文件类和常用方法
- struts2拦截器转化敏感字符
- linux内存映射mmap原理分析