There are three methods to obtain LayoutInflater: LayoutInflater inflater = (LayoutInflater) context. getSystemService (Context. LAYOUT_INFLATER_SERVICE); View layout = inflater. inflate (R. layout. main, null); LayoutInflater inflater = LayoutInflater. from (context); (this method is actually the first method, refer to the source code) View layout = inflater. inflate (R. layout. main, null); LayoutInflater inflater = getLayoutInflater (); (this function can be used in the Activity. It is actually a function of window under the View subclass.) View layout = inflater. inflate (R. layout. main, null); usage: public class MyInflate extends Activity {private TextView TV; public void OnCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // setContentView (R. layout. main); // TV = (TextView) findViewById (R. id. TV); LayoutInflater inflate = LayoutInflater. from (this); View view = inflate. inflate (R. layout. main, null); setContentView (view );}}