package com.dbs.consent.demo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dbs.consent.demo.R;
import com.dbs.consent.demo.model.CategoryVO;

import java.util.ArrayList;

import androidx.appcompat.app.AppCompatActivity;

public class CategoryAdapter extends BaseAdapter {

  private AppCompatActivity mActivity;
  public ArrayList arrayList;

  public CategoryAdapter(AppCompatActivity mActivity, ArrayList arrayList) {
    this.mActivity = mActivity;
    this.arrayList = arrayList;
  }

  @Override
  public int getCount() {
    return arrayList.size();
  }

  @Override
  public Object getItem(int position) {
    return arrayList.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  class ViewHolder {
    public TextView tvTitle;
  }


  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;
    ViewHolder holder = null;
    CategoryVO categoryVO = null;

    if (v == null) {
      holder = new ViewHolder();
      v = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_layout, parent, false);
      holder.tvTitle = (TextView) v.findViewById(R.id.spinnerTarget);

      v.setTag(holder);
    } else {
      holder = (ViewHolder) v.getTag();
    }

    String textNm = "";
    categoryVO = (CategoryVO) arrayList.get(position);
    textNm = categoryVO.getCategoryName();


    holder.tvTitle.setText(textNm);

    return v;
  }

}

