gpt4 book ai didi

android - 高效地创建 LayoutInflater

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:50 26 4
gpt4 key购买 nike

我的问题是创建 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;
}

关于android - 高效地创建 LayoutInflater,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11934578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com