public class MyPullLoadRecycler extends RecyclerView.Adapter{
private Context context; private Listdata;
public MyPullLoadRecycler(Context context, Listdata) {
this.context = context;
this.data = data;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragmenta_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
DisplayImageOptions options = ImageLoaderUtils.getOptions();
ImageLoader.getInstance().displayImage(data.get(position).getImages().get(0),holder.news_image,options);
holder.news_id.setText(data.get(position).getId()+"");
holder.news_ga_prefix.setText(data.get(position).getGa_prefix()+"");
holder.news_title.setText(data.get(position).getTitle());
holder.news_type.setText(data.get(position).getType()+"");
}
@Override
public int getItemCount() {
return data.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
private ImageView news_image;
private TextView news_title;
private TextView news_id;
private TextView news_type;
private TextView news_ga_prefix;
public ViewHolder(View itemView) {
super(itemView);
news_image=itemView.findViewById(R.id.news_image);
news_id=itemView.findViewById(R.id.news_id);
news_title=itemView.findViewById(R.id.news_title);
news_type=itemView.findViewById(R.id.news_type);
news_ga_prefix=itemView.findViewById(R.id.news_ga_prefix);
}
}
//---------------------------------------------
public class MyTiaoZhuanAdapter extends RecyclerView.Adapter{ private final int TYPE_FIRST=0; private final int TYPE_TWO=1; private Context context; private Listdata; public MyTiaoZhuanAdapter(Context context, Listdata) {
this.context = context;
this.data = data;
}
@Override
public int getItemViewType(int position) {
if (data.get(position).getImages().isEmpty()){
return TYPE_FIRST;
}else {
return TYPE_TWO;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType==TYPE_FIRST){
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.first_item, parent, false);
return new FirstHolder(view);
}else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.two_item, parent, false);
return new TwoHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof FirstHolder)
{
FirstHolder firstviewholder= (FirstHolder) holder;
firstviewholder.title.setText(data.get(position).getTitle());
firstviewholder.type.setText(data.get(position).getType()+"");
firstviewholder.id.setText(data.get(position).getId()+"");
}
else if (holder instanceof TwoHolder){
TwoHolder twoholder= (TwoHolder) holder;
twoholder.title.setText(data.get(position).getTitle());
twoholder.type.setText(data.get(position).getType()+"");
twoholder.id.setText(data.get(position).getId()+"");
DisplayImageOptions options = ImageLoaderUtils.getOptions();
ImageLoader.getInstance().displayImage(data.get(position).getImages().get(0),twoholder.imageView,options);
}
}
@Override
public int getItemCount() {
return data==null?0:data.size();
}
public static class FirstHolder extends RecyclerView.ViewHolder{
private TextView id;
private TextView title;
private TextView type;
public FirstHolder(View itemView) {
super(itemView);
id=itemView.findViewById(R.id.tz_id);
type=itemView.findViewById(R.id.tz_type);
title=itemView.findViewById(R.id.tz_title);
}
}
public static class TwoHolder extends RecyclerView.ViewHolder{
private TextView id;
private TextView title;
private TextView type;
private ImageView imageView;
public TwoHolder(View itemView) {
super(itemView);
id=itemView.findViewById(R.id.tz_id);
type=itemView.findViewById(R.id.tz_type);
title=itemView.findViewById(R.id.tz_title);
imageView=itemView.findViewById(R.id.tz_image);
}
}
//--------------------------
public class MyGridAdapter extends BaseAdapter { private Context context; private Listdata; public MyGridAdapter(Context context, Listdata) {
this.context = context;
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int i) {
return data.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if (view==null){
viewHolder=new ViewHolder();
view=View.inflate(context, R.layout.gridview_item,null);
viewHolder.imageView=view.findViewById(R.id.iv_head);
viewHolder.color=view.findViewById(R.id.zt_color);
viewHolder.id=view.findViewById(R.id.zt_id);
viewHolder.description=view.findViewById(R.id.description);
viewHolder.name=view.findViewById(R.id.zt_name);
view.setTag(viewHolder);
}else {
viewHolder= (ViewHolder) view.getTag();
}
viewHolder.color.setText(data.get(i).getColor()+"");
viewHolder.name.setText(data.get(i).getName());
viewHolder.description.setText(data.get(i).getDescription());
viewHolder.id.setText(data.get(i).getId()+"");
// DisplayImageOptions options = ImageLoaderUtils.getOptions();
//ImageLoader.getInstance().displayImage(data.get(i).getThumbnail(),viewHolder.imageView,options);
TwoImageUtils.loadImage(data.get(i).getThumbnail(),viewHolder.imageView);
return view;
}
class ViewHolder{
XCRoundRectImageView imageView;
TextView name;
TextView id;
TextView color;
TextView description;
}