public class Gride extends BaseAdapter { private List<Bean.DataBean.EssayBean> data; private Context context; public Gride(List<Bean.DataBean.EssayBean> data, Context context) { this.data= data; this.context = context; } @Override public int getCount() { // TODO Auto-generated method stub return data.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return data.get(arg0); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Honder honder =null; //做适配器的优化 if (convertView==null) { convertView=View.inflate(context, R.layout.gride, null); honder = new Honder(); honder.img=(ImageView) convertView.findViewById(R.id.img); honder.name= (TextView) convertView.findViewById(R.id.name); convertView.setTag(honder); }else{ honder=(Honder) convertView.getTag(); } String s = data.get(position).getAuthor_list().get(0).getUser_name(); honder.name.setText(s); String ss = data.get(position).getAuthor_list().get(0).getWeb_url(); ImageLoader.getInstance().displayImage(ss, honder.img, ImageLoaderUtil.getDefaultOption()); return convertView; } class Honder{ ImageView img; TextView name; } }
适配器
最新推荐文章于 2024-09-24 17:25:47 发布