Advertisement
ricky_yulianto

Untitled

Jul 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. package codelabs.ambarrukmo.adapter;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.support.annotation.NonNull;
  6. import android.support.v7.widget.RecyclerView;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12.  
  13. import com.google.gson.Gson;
  14. import com.squareup.picasso.Picasso;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. import butterknife.BindView;
  20. import butterknife.ButterKnife;
  21. import codelabs.ambarrukmo.R;
  22. import codelabs.ambarrukmo.activity.PromoCategoryActivity;
  23. import codelabs.ambarrukmo.model.CategoryListPromo;
  24.  
  25. public class CategoryPromoAdapter extends RecyclerView.Adapter<CategoryPromoAdapter.ViewHolder> {
  26.  
  27. private Context context;
  28. private List<CategoryListPromo.DATABean> mItems = new ArrayList<>();
  29. private String TAG = getClass().getSimpleName();
  30. public CategoryPromoAdapter(Context context) {
  31. this.context = context;
  32. }
  33.  
  34. public List<CategoryListPromo.DATABean> getItems() {
  35. return mItems;
  36. }
  37.  
  38. public void setData(List<CategoryListPromo.DATABean> items) {
  39. mItems = items;
  40. notifyDataSetChanged();
  41. }
  42.  
  43.  
  44. @NonNull
  45. @Override
  46. public CategoryPromoAdapter.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int position) {
  47. View v = (LayoutInflater.from(context).inflate(R.layout.item_category_promo, parent, false));
  48. return new ViewHolder(v);
  49. }
  50.  
  51.  
  52. @Override
  53. public void onBindViewHolder(@NonNull CategoryPromoAdapter.ViewHolder holder, int position) {
  54. Picasso.get()
  55. .load(mItems.get(position).getCat_promo_image())
  56. .placeholder(R.drawable.img_step2)
  57. .error(R.drawable.img_step2)
  58. .into(holder.imgItemCategory);
  59. holder.tvTitleCategory.setText(mItems.get(position).getCat_promo_title());
  60.  
  61. }
  62.  
  63. @Override
  64. public int getItemCount() {
  65. return mItems.size();
  66. }
  67.  
  68. public class ViewHolder extends RecyclerView.ViewHolder{
  69. @BindView(R.id.img_item_category)
  70. ImageView imgItemCategory;
  71. @BindView(R.id.tv_title_category)
  72. TextView tvTitleCategory;
  73.  
  74.  
  75.  
  76.  
  77. public ViewHolder(View view) {
  78. super(view);
  79. ButterKnife.bind(this, view);
  80.  
  81. view.setOnClickListener(new View.OnClickListener() {
  82. @Override
  83. public void onClick(View v) {
  84. Intent intent = new Intent(v.getContext(), PromoCategoryActivity.class);
  85. intent.putExtra("promo", new Gson().toJson(mItems.get(getAdapterPosition())));
  86. context.startActivity(intent);
  87. // intent.putExtra("category_promo", new Gson().toJson(mItems.get(getAdapterPosition())));
  88. // intent.putExtra("query_param", "cat_promo_id");
  89. // intent.putExtra("value_param",mItems.get(getAdapterPosition()).getCat_promo_id());
  90. // context.startActivity(intent);
  91.  
  92. }
  93. });
  94.  
  95.  
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement