Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a20621646_k2;
- import android.content.Context;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.TextView;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import java.util.ArrayList;
- public class ClothesAdapter extends ArrayAdapter<Clothes> {
- private final Context context;
- private final ArrayList<Clothes> clothesList;
- public ClothesAdapter(Context context, ArrayList<Clothes> clothesList) {
- super(context, 0, clothesList);
- this.context = context;
- this.clothesList = clothesList;
- }
- @NonNull
- @Override
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
- View listItem = convertView;
- if (listItem == null) {
- listItem = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
- }
- Clothes currentClothes = clothesList.get(position);
- TextView typeTextView = listItem.findViewById(android.R.id.text1);
- typeTextView.setText(currentClothes.getType());
- TextView detailsTextView = listItem.findViewById(android.R.id.text2);
- String details = "Price: $" + currentClothes.getPrice() +
- ", Quantity: " + currentClothes.getQuantity() +
- ", Origin: " + currentClothes.getOriginCountry();
- detailsTextView.setText(details);
- Log.d("20621646", "ClothesAdapter: getView - Position " + position);
- return listItem;
- }
- }
Add Comment
Please, Sign In to add comment