listview下如何获取view的方法

当你想在View中获取数据时这个

LayoutInflater.from(mContext).inflate(R.layout.list_item,parent,false)

有用。它会将View中设置的图片、字符串等所有数据保存起来。然后你就可以分拣了。

public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item,parent,false);
ImageView img_icon = (ImageView) convertView.findViewById(R.id.imgtou);
TextView txt_aName = (TextView) convertView.findViewById(R.id.name);
TextView txt_aSpeak = (TextView) convertView.findViewById(R.id.says);
img_icon.setBackgroundResource(mData.get(position).getaIcon());
txt_aName.setText(mData.get(position).getaName());
txt_aSpeak.setText(mData.get(position).getaSpeak());
return convertView;
}
posted @ 2022-04-15 14:48  LINE智能  阅读(235)  评论(0编辑  收藏  举报