码迷,mamicode.com
首页 > 移动开发 > 详细

Android开发-- findViewById()方法得到空指针

时间:2014-09-28 21:18:35      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   sp   div   on   c   cti   

如果想通过调用findViewById()方法获取到相应的控件,必须要求当前Activity的layout通过setContentView. 如果你通过其他方法添加了一个layout,如需获取这个layout中的View对象,首先需inflate这个layout,然后在该layout上调用findViewById().

1 View v = inflater.inflate(id_number_of_layout);
2 View innerView = v.findViewById(id_number_of_view_inside_v);

 

Android开发-- findViewById()方法得到空指针

标签:android   style   blog   color   sp   div   on   c   cti   

原文地址:http://www.cnblogs.com/feiling/p/3998684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!