adapter里面重写的getView中convertView.getTag;什么意思
1个回答
推荐于2016-11-28 · 知道合伙人影视综艺行家
关注
展开全部
把查找的view缓存起来方便多次重用
不用重新构建VIEW,利用系统中缓存的VIEW,可以提高效率
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder;
if(convertView==null){
LayoutInflater inflater=LayoutInflater.from(context);
convertView=inflater.inflate(R.layout.zixun_list_item, null);
viewHolder=new ViewHolder();
}else{
viewHolder=(ViewHolder) convertView.getTag();
}
initView(position,convertView,viewHolder);
return convertView;
}
private void initView(int position,View convertView,ViewHolder viewHolder){
viewHolder.tvTitle=(TextView) convertView.findViewById(R.id.mytextview);
viewHolder.tvTitle.setText(list.get(position).getTittleString());
convertView.setTag(viewHolder);
}
class ViewHolder{
TextView tvTitle;
}
不用重新构建VIEW,利用系统中缓存的VIEW,可以提高效率
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder;
if(convertView==null){
LayoutInflater inflater=LayoutInflater.from(context);
convertView=inflater.inflate(R.layout.zixun_list_item, null);
viewHolder=new ViewHolder();
}else{
viewHolder=(ViewHolder) convertView.getTag();
}
initView(position,convertView,viewHolder);
return convertView;
}
private void initView(int position,View convertView,ViewHolder viewHolder){
viewHolder.tvTitle=(TextView) convertView.findViewById(R.id.mytextview);
viewHolder.tvTitle.setText(list.get(position).getTittleString());
convertView.setTag(viewHolder);
}
class ViewHolder{
TextView tvTitle;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询