I went through some tutorials, and in the Android Doc, it says not to access LayoutInflater directly when instantiating it. Example from the google Doc:
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
The tutorial I went through is this one:
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
So what I don’t really understand is what the difference is besides the obvious different code. Any explanation much appreciated. I assume that the Android Doc should be the one we follow, but I am not sure if it makes a difference.
If you open up the Android source you can see that the LayoutInflator.from method looks like so:
That means the two lines of code in your question do the same thing. Not sure what the tutorial you read says exactly but I don’t see any difference in functionality. Using the
frommethod is nice since it requires a little less typing, that’s it.