现在的位置: 首页 > 综合 > 正文

findviewbyid return null for custom view

2012年10月13日 ⁄ 综合 ⁄ 共 659字 ⁄ 字号 评论关闭

  i invoke findViewById method like this:

view view = LayoutInflater.from(this).inflate(R.layout.xxx,null);
Customview myView = view.findviewbyid(R.id.xy);
....

setcontentView(view);

  but it keeps return null . after searchs, i found that i shoud call findviewbyid() before setcontentview method. you can also do like this:

You call this method:

inflater.inflate(R.layout.picture_method_option, null, false);
And you ignore the result. The last parameter, false, indicates to not add the content of the XML layout to the layout root (which you set to null anyway.) You need to do something like this:

View v = inflater.inflate(R.layout.picture_method_option, null, false);
addView(v);
Or:

inflater.inflate(R.layout.picture_method_option, this, true);

 

抱歉!评论已关闭.