AleksandarH

ClothesAdapter

Dec 12th, 2023 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.example.a20621646_k2;
  2.  
  3. import android.content.Context;
  4. import android.util.Log;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.TextView;
  10.  
  11. import androidx.annotation.NonNull;
  12. import androidx.annotation.Nullable;
  13.  
  14. import java.util.ArrayList;
  15.  
  16. public class ClothesAdapter extends ArrayAdapter<Clothes> {
  17.  
  18.     private final Context context;
  19.     private final ArrayList<Clothes> clothesList;
  20.  
  21.     public ClothesAdapter(Context context, ArrayList<Clothes> clothesList) {
  22.         super(context, 0, clothesList);
  23.         this.context = context;
  24.         this.clothesList = clothesList;
  25.     }
  26.  
  27.     @NonNull
  28.     @Override
  29.     public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  30.         View listItem = convertView;
  31.  
  32.         if (listItem == null) {
  33.             listItem = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
  34.         }
  35.  
  36.         Clothes currentClothes = clothesList.get(position);
  37.  
  38.         TextView typeTextView = listItem.findViewById(android.R.id.text1);
  39.         typeTextView.setText(currentClothes.getType());
  40.  
  41.         TextView detailsTextView = listItem.findViewById(android.R.id.text2);
  42.         String details = "Price: $" + currentClothes.getPrice() +
  43.                 ", Quantity: " + currentClothes.getQuantity() +
  44.                 ", Origin: " + currentClothes.getOriginCountry();
  45.         detailsTextView.setText(details);
  46.  
  47.         Log.d("20621646", "ClothesAdapter: getView - Position " + position);
  48.  
  49.         return listItem;
  50.     }
  51. }
Add Comment
Please, Sign In to add comment