一、对于一个没有被载入或者想要动态载入的界面,都须要使用LayoutInflater.inflate()来载入; java
二、对于一个已经载入的界面,就能够使用Activiyt.findViewById()方法来得到其中的界面元素。 api
inflate 方法 经过 sdk 的 api 文档,能够知道该方法有如下几种过载形式,返回值均是 View 对象,以下: spa
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);