0

My question is basically in the title but I am curious if there is a difference between context.getLayoutInflater() and LayoutInflater.from(context). For example:

View contentView = getActivity().getLayoutInflater().inflate(R.layout.some_layout, null);

and

View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.some_layout, null);

Sean Hill
  • 1,297
  • 1
  • 13
  • 21

1 Answers1

1

No, they do the same thing. I see the from version used more these days, but they will do the same thing.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Is there any reason why there are two different ways of doing this same thing? Any differences in performance, or anything else worth considering? – Sean Hill Apr 06 '16 at 18:13
  • From is actually more general- it can inflate from any Context, not just an activity. There are a few cases where services have a UI, its needed for them. As for two ways to do the same thing- there's dozens of people working on the Android SDK, sometimes both of them see the same need and add a function to fill it. – Gabe Sechan Apr 06 '16 at 18:16