我的问题是创建LayoutInflater
实例的最佳方法是什么?是否有任何区别?
LayoutInflater inflater = LayoutInflater.from(context);
并且
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
哪种方案更好?其他解决方案也可以。谢谢。
我的问题是创建LayoutInflater
实例的最佳方法是什么?是否有任何区别?
LayoutInflater inflater = LayoutInflater.from(context);
并且
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
如果您查看LayoutInflater.java源文件,您会发现。
/**
* 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;
}