LayoutInflater

一、對於一個沒有被載入或者想要動態載入的界面,都須要使用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);
相關文章
相關標籤/搜索