Include Layout programmatically in Android

The easiest way to innclude a XML layout into another programmatically using LayoutInflater in Android.


Libraries

Code Snippet
// Init Inflater
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

// Get Parent
ViewGroup parent = (ViewGroup)findViewById(R.id.id_of_parent_to_include_layout);

// Include
View view = inflater.inflate(R.layout.layout_to_include, parent);


Implementation

That's it.





Comments
  • mode_editWrite a comment



  • forumComments




Embed Code

We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 0 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    LayoutInflater
    Android
    XML



    Informations

    posted on 2016-10-26 15:18:48

    viewed 186 times

    snippet's UUID is 5810ad38385b2

    Similar Snippets