三中常用的打气筒

来源:互联网 发布:小海淘宝助手超级版 编辑:程序博客网 时间:2024/04/26 09:30
public View getView(int position, View convertView, ViewGroup parent) {

//[1]想办法把我们自己定义的布局转换成一个view对象 就可以了
View view;
if (convertView == null) {
//创建新的view对象   可以通过打气筒把一个布局资源转换成一个view对象 
//resource 就是 我们定义的布局文件 

//[一☆☆☆☆]获取打气筒服务
// view = View.inflate(getApplicationContext(), R.layout.item, null);

//[二☆☆☆☆]获取打气筒服务
// view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, null);

//[三☆☆☆☆]获取打气筒服务
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
   view = inflater.inflate(R.layout.item, null);


}else {
//复用历史缓存对象 
view = convertView;

}



return view;
}

}
原创粉丝点击