import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;java
import com.bumptech.glide.Glide;android
import java.util.ArrayList;ide
/**
* Created by lenovo on 2017/9/6.
*/
public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {this
private ArrayList<News> list;
private Context context;.net
public MyRecyclerAdapter(ArrayList list, Context context) {
this.list = list;
this.context = context;
}get
@Override
public int getItemViewType(int position) {
return list.get(position).getType();
}it
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder = null;
if(viewType==0){
View view = LayoutInflater.from(context).inflate(R.layout.item_layout, parent, false);
viewHolder = new ViewHolder1(view);
}
if(viewType==1){
View view = LayoutInflater.from(context).inflate(R.layout.item_layout2, parent, false);
viewHolder = new ViewHolder2(view);
}io
return viewHolder;
}class
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int type = list.get(position).getType();
if(type==0){
Glide.with(context).load(list.get(position).getPic().get(0).getThumbnail_pic()).into(((ViewHolder1)holder).img1);
Glide.with(context).load(list.get(position).getPic().get(1).getThumbnail_pic()).into(((ViewHolder1)holder).img2);
Glide.with(context).load(list.get(position).getPic().get(2).getThumbnail_pic()).into(((ViewHolder1)holder).img3);
((ViewHolder1)holder).text1Tv.setText(list.get(position).getAuthor_name());
}
if(type==1){
Glide.with(context).load(list.get(position).getPic().get(0).getThumbnail_pic()).into(((ViewHolder2)holder).img);
((ViewHolder2)holder).text2Tv.setText(list.get(position).getAuthor_name());
}
}import
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder1 extends RecyclerView.ViewHolder {
private ImageView img1;
private ImageView img2;
private ImageView img3;
private TextView text1Tv;
public ViewHolder1(View itemView) {
super(itemView);
img1 = (ImageView) itemView.findViewById(R.id.img1);
img2 = (ImageView) itemView.findViewById(R.id.img2);
img3 = (ImageView) itemView.findViewById(R.id.img3);
text1Tv = (TextView) itemView.findViewById(R.id.tv_text1);
}
}
public class ViewHolder2 extends RecyclerView.ViewHolder {
private ImageView img;
private TextView text2Tv;
public ViewHolder2(View itemView) {
super(itemView);
img = (ImageView) itemView.findViewById(R.id.img);
text2Tv = (TextView) itemView.findViewById(R.id.tv_text2);
} } }