There is a way to get layoutInflater:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
and
use outside of your activity
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE );
Within your activity
LayoutInflater inflater = getLayoutInflater();
Check this
If you open up the Android source you can see that the LayoutInflator.from method looks like so:
/**
* Obtains the LayoutInflater from the given context.
*/
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}
and there is no difference
As long as the Activity or Window that calls getLayoutInflater()
has the same Context that would call getSystemService()
, there is no difference.