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 MyAdapter extends BaseAdapter {
private List<News> list;
private LayoutInflater inflater;
private News news;
private Context context;
public MyAdapter(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_news_top_item, null);
holder.iv_news_photo = (ImageView)convertView.findViewById(R.id.iv_news_photo);
holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title_news_top_item);
holder.tv_Description = (TextView) convertView.findViewById(R.id.tv_description_news_top_item);
holder.tv_count = (TextView)convertView.findViewById(R.id.tv_news_count_comments);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
news = list.get(position);
holder.tv_title.setText(news.getNewsTitle());
holder.tv_Description.setText(news.getNewsContent());
holder.tv_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_news_photo.setImageURI(Uri.fromFile(file));
}else{
holder.iv_news_photo.setImageResource(R.drawable.base_list_default_icon);
}
return convertView;
}
public static class ViewHolder {
TextView tv_title;
TextView tv_Description;
ImageView iv_news_photo;
TextView tv_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日

最近浏览