android - Difference between setContentView and LayoutInflater -
i creating tabs list several fragments. have noticed that, in main activity, used setcontentview layout xml , use findviewbyid corresponding ui element config.
setcontentview(r.layout.fragment_tabs); mtabhost = (tabhost)findviewbyid(android.r.id.tabhost); mtabhost.setup(); mtabmanager = new tabmanager(this, mtabhost, android.r.id.tabcontent); however, in different fragment class, have use inflater instead.
view v = inflater.inflate(r.layout.webview, container, false); webview mybrowser=(webview)v.findviewbyid(r.id.mybrowser); and both function used layout xml create object, why there difference? first 1 use during oncreate, , second 1 during oncreateview? in situation should choose either of them?
setcontentview activity method only. each activity provided framelayout id "@+id/content" (i.e. content view). whatever view specify in setcontentview view activity. note can pass instance of view method, e.g. setcontentview(new webview(this)); version of method using inflate view behind scenes.
fragments, on other hand, have lifecycle method called oncreateview returns view (if has one). common way inflate view in xml , return in method. in case need inflate though. fragments don't have setcontentview method
Comments
Post a Comment