首页>代码>android 仿网易新闻客户端源码都有>/neteaseNews/src/com/zm/netease/adapter/PicAdapter.java
package com.zm.netease.adapter;

import java.io.File;
import java.util.List;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zm.netease.R;
import com.zm.netease.http.HttpRequestService;
import com.zm.netease.vo.News;

public class PicAdapter extends BaseAdapter {
	private List<News> list;
	private LayoutInflater inflater;
	private News news;
	private Context context;
	
	public PicAdapter(List<News> list,Context context) {
		this.context = context;
		this.list = list;
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.layout_pic_item, null);
			holder.iv_pic_photo = (ImageView)convertView.findViewById(R.id.iv_pic_photo);
			holder.tv_pic_title = (TextView) convertView.findViewById(R.id.tv_pic_title);
			holder.tv_pic_comments_count = (TextView) convertView.findViewById(R.id.tv_pic_comments_count);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		news = list.get(position);
	    holder.tv_pic_title.setText(news.getNewsTitle());
		holder.tv_pic_comments_count.setText(news.getCommentsCount()+"跟帖");
			if(news.getPhotos()!=null){
				String photoName=news.getPhotos().get(0).getNewsFilmResourceUrl();
				String photoUrl=context.getResources().getString(R.string.android_url);
				File file = new File(photoUrl,photoName.split("/")[1]);
				//从后台读取照片
				if(!file.exists()){
					new HttpRequestService().putPhoto(photoName, file, context);
				}
				holder.iv_pic_photo.setImageURI(Uri.fromFile(file));
			}else{
				holder.iv_pic_photo.setImageResource(R.drawable.biz_pics_set_item_icon);
			}		
		
		return convertView;
	}
	public static class ViewHolder {
		TextView tv_pic_title;
		ImageView iv_pic_photo;
		TextView tv_pic_comments_count;
	}
	
}
最近下载更多
宝藏男孩  LV1 2023年10月6日
2754137495  LV6 2023年3月29日
yang886  LV21 2023年3月5日
7894561  LV1 2022年6月7日
wangyunhao  LV10 2022年5月17日
511076827  LV33 2022年4月11日
张信哲  LV8 2021年5月7日
wangwenzhong  LV9 2020年12月25日
JavaPro_Allen  LV9 2020年10月20日
zhi_you90  LV1 2020年6月14日
最近浏览更多
666ing  LV2 2023年12月27日
学习112  LV2 2023年12月21日
微信网友_6768517354180608  LV1 2023年12月7日
花落亦知秋 2023年11月27日
暂无贡献等级
hhhhhz  LV7 2023年11月14日
宝藏男孩  LV1 2023年10月6日
panwill  LV5 2023年8月18日
wlhl1h  LV1 2023年7月17日
Yanguu 2023年7月11日
暂无贡献等级
wanglei92  LV2 2023年6月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友