开发者

getLayoutInflator() in Android

I have read the android documen开发者_Go百科tation about getLayoutInflator and I am still not understanding what it does. Can someone give me a use case for this method or may be during what time would you want to call getLayoutInflator?


XML Layouts in Android need to be Inflated (parsed into View objects) before they are used. getLayoutInflator() gets you an instance of the LayoutInflator that will allow you to manually inflate layouts for specific uses.

One example being in a Custom ArrayAdapter to populate a ListView with a Custom Layout.

You need to manually inflate and populate your desired Layout for each individual list item in the ArrayAdapter's overridden getView() method.


Use setContentView() when you're in an Activity. That method inflates the layout and displays the selected layout as the view for that Activity. But when you're NOT in an Activity and you need to work with a layout file, you have to inflate it to get access to the view objects in the XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜