Last active
November 11, 2018 05:07
-
-
Save girish3/cb5843b73d4c5eb941cf8077a6f7e813 to your computer and use it in GitHub Desktop.
[Layout Inflater] Ways to get layout inflator object and inflate the view. #android_snippet #android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if you are in an activity | |
LayoutInflater inflater = getLayoutInflater(); | |
// If you have the context | |
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
// or in a cleaner way, from() uses system service interally so its the same inflater | |
LayoutInflater inflater = LayoutInflater.from(context); | |
// inflating a view | |
// if you need to attach the inflated to rootView, returned view will be rootView. | |
// 3rd parameter is attach_to_root | |
inflater.inflate(R.layout.my_layout, rootView, true); | |
// or if not, returned view will be the inflated view. | |
inflater.inflate(R.layout.my_layout, null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment