我可以知道
的意思吗 public View getView(int position, View view, ViewGroup parent){
if (view ==null)
view = getLayoutInflater().inflate(R.layout.listview_item, parent, false);
}
- 为什么包含三个参数,这三个参数的含义是什么
- layout inflater 它必须与 view 一起工作吗?为什么?
任何人都可以向我解释谢谢!
最佳答案
LayoutInflater
有两个相关的 inflate
重载:
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
public View inflate (int resource, ViewGroup root)
第二个参数是您要引用的 View ,作为您正在膨胀的 View 的根。如果 attachToRoot 为真,它将成为膨胀 View 的父 View 。如果没有,它只会帮助创建正确的布局。
如果您使用第二个重载,attachToRoot 被假定为 true,并且如果您提供(可选的)根,它将作为父 View 自动附加到扩展 View 。
关于java - Android getLayoutInflater().inflate 详解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099396/