我正在创建一个包含多个片段的选项卡列表.我注意到,在主要活动中,我曾经setContentView获得布局xml并用于findViewById获取相应的UI元素配置.
setContentView(R.layout.fragment_tabs);
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabManager = new TabManager(this, mTabHost, android.R.id.tabcontent);
Run Code Online (Sandbox Code Playgroud)
但是,在不同的片段类中,我必须使用inflater.
View v = inflater.inflate(R.layout.webview, container, false);
WebView myBrowser=(WebView)v.findViewById(R.id.mybrowser);
Run Code Online (Sandbox Code Playgroud)
并且这两个函数都用于获取布局xml来创建一个对象,为什么会有区别?是第一个使用期间onCreate,第二个期间使用onCreateView?在什么情况下我应该选择其中之一?
layout android xml-parsing android-lifecycle layout-inflater