public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private ArrayList<Android> android;
Context context;
private ImageView img;
public DataAdapter(Context contextN, ArrayList<Android> android) {
this.android = android;
this.context=contextN;
}
@Override
public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_list, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(DataAdapter.ViewHolder viewHolder, int i) {
viewHolder.tv_name.setText(android.get(i).getOffer());
viewHolder.tv_version.setText(android.get(i).getOfferType());
Picasso.with(context).load(android.get(i).getImg()).transform(new CircleTransform()).into(img);
}
@Override
public int getItemCount() {
return android.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv_name,tv_version,tv_api_level;
public ViewHolder(View view) {
super(view);
tv_name = (TextView)view.findViewById(R.id.tv_name);
tv_version = (TextView)view.findViewById(R.id.tv_version);
img = (ImageView) view.findViewById(R.id.img);
context = itemView.getContext();
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int itemPosition = getLayoutPosition();
Toast.makeText(context, "" + itemPosition, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context,Show.class);
intent.putExtra("name",""+android.get(itemPosition).getOffer());
intent.putExtra("img",""+android.get(itemPosition).getImg());
context.startActivity(intent);
}
});
}
}
}