package cn.zhaoliang5156.zhaoliang2018727.adapter;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.List;
public class BannerAdapter extends PagerAdapter {
private List<ImageView> imageViewList;
public BannerAdapter(List<ImageView> imageViewList) {
this.imageViewList = imageViewList;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = imageViewList.get(position % imageViewList.size());
ViewGroup viewGroup = (ViewGroup) imageView.getParent();
if (viewGroup != null) {
viewGroup.removeAllViews();
}
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
package cn.zhaoliang5156.zhaoliang2018727.adapter;
import android.content.Context;
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.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import cn.zhaoliang5156.zhaoliang2018727.R;
import cn.zhaoliang5156.zhaoliang2018727.bean.UINewsBean;
public class NewsListAdapter extends BaseAdapter {
private Context context;
private List<UINewsBean.DataBean> dataBeans;
public NewsListAdapter(Context context, List<UINewsBean.DataBean> dataBeans) {
this.context = context;
this.dataBeans = dataBeans;
}
@Override
public int getCount() {
return dataBeans.size();
}
@Override
public UINewsBean.DataBean getItem(int position) {
return dataBeans.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.news_item, null, false);
viewHolder.ivIcon = convertView.findViewById(R.id.iv_icon);
viewHolder.tvDesc = convertView.findViewById(R.id.tv_desc);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
ImageLoader.getInstance().displayImage(dataBeans.get(position).getMiniimg().get(0).getSrc(), viewHolder.ivIcon);
viewHolder.tvDesc.setText(dataBeans.get(position).getBrief());
return convertView;
}
class ViewHolder {
ImageView ivIcon;
TextView tvDesc;
}
}