How To: Get current layout object on Android

by Stephen Fluin 2009.06.14

Android development is a little unclear if you need to get access to an object representing a layout loaded from a .xml layout file. The way to accomplish this is to use a LayoutInflater. The purpose of this class is to instantiate an object capable of openening the .xml file via its reference integer and returning a reference to the in-memory Layout object.

Example

LayoutInflater inflater = getLayoutInflater();
LinearLayout l = (LinearLayout) inflater.inflate(R.layout.main,null);

permalink