LayoutInflater
程序员文章站
2024-02-10 23:52:58
...
1、对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来载入;
2、对于一个已经载入的界面,就可以使用Activiyt.findViewById()方法来获得其中的界面元素。
inflate 方法 通过 sdk 的 api 文档,可以知道该方法有以下几种过载形式,返回值均是 View 对象,如下:
public View inflate (int resource, ViewGroup root);
public View inflate (XmlPullParser parser, ViewGroup root);
public View inflate (XmlPullParser parser, ViewGroup root, boolean attachToRoot);
public View inflate (int resource, ViewGroup root, boolean attachToRoot);
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom, (ViewGroup)findViewById(R.id.test));
//EditText editText = (EditText)findViewById(R.id.content);
// error
EditText editText = (EditText)view.findViewById(R.id.content);
转载于:https://my.oschina.net/u/867543/blog/541846
上一篇: LayoutInflater
下一篇: Android的蓝牙数据传输