Guest User

Apapter

a guest
May 25th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. public class CoinlogoAdapter extends PagerAdapter {
  2.  
  3.     private Context context;
  4.     private List<Coinlogo> listCoin;
  5.  
  6.     public CoinlogoAdapter(Context context, List<Coinlogo> listCoin) {
  7.         this.context = context;
  8.         this.listCoin = listCoin;
  9.     }
  10.  
  11.     @Override
  12.     public int getCount() {
  13.         return listCoin.size();
  14.     }
  15.  
  16.     @Override
  17.     public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
  18.         super.destroyItem(container, position, object);
  19.     }
  20.  
  21.     @Override
  22.     public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
  23.         return view.equals(object);
  24.     }
  25.  
  26.     @Override
  27.     public int getItemPosition(@NonNull Object object) {
  28.         return super.getItemPosition(object);
  29.     }
  30.  
  31.     @NonNull
  32.     @Override
  33.     public Object instantiateItem(@NonNull ViewGroup container, int position) {
  34.         View view = LayoutInflater.from(context).inflate(R.layout.item_coin, container, false);
  35.  
  36.         ImageView ivImage = view.findViewById(R.id.iv_image);
  37.         TextView tvTitle = view.findViewById(R.id.tv_title);
  38.         TextView tvYear = view.findViewById(R.id.tv_year);
  39.         TextView tvStamp = view.findViewById(R.id.tv_stamp);
  40.         TextView tvCondition = view.findViewById(R.id.tv_condition);
  41.         TextView tvKant = view.findViewById(R.id.tv_kant);
  42.         TextView tvMagnet = view.findViewById(R.id.tv_magnet);
  43.         TextView tvGurt = view.findViewById(R.id.tv_gurt);
  44.         TextView tvPrice = view.findViewById(R.id.tv_price);
  45.  
  46.         ivImage.setImageResource(listCoin.get(position).getImage());
  47.         tvTitle.setText(listCoin.get(position).getNominal());
  48.         tvYear.setText(listCoin.get(position).getYear());
  49.         tvStamp.setText(listCoin.get(position).getStamp());
  50.         tvCondition.setText(listCoin.get(position).getCondition());
  51.         tvKant.setText(listCoin.get(position).getKant());
  52.         tvMagnet.setText(listCoin.get(position).getMagnet());
  53.         tvGurt.setText(listCoin.get(position).getGurt());
  54.         tvPrice.setText(listCoin.get(position).getPrice());
  55.  
  56.         view.setOnClickListener(v -> Toast.makeText(context, "" + listCoin, Toast.LENGTH_SHORT).show());
  57.  
  58.         container.addView(view);
  59.  
  60.         return view;
  61.     }
  62. }
Add Comment
Please, Sign In to add comment