package com.example.beijing_daxing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;

import com.example.beijing_daxing.R;
import com.example.beijing_daxing.databinding.ItemHomepageBinding;
import com.example.beijing_daxing.been.HomeIcon;

import java.util.List;

/**
 * @author wanghao
 * @date 2023/3/14  10:17
 */
public class HomePageAdapter extends BaseAdapter{
    private List<HomeIcon> list;
    private Context context;
    private LayoutInflater inflater;
    public HomePageAdapter(List<HomeIcon> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

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

    @Override
    public Class getItem(int i) {
        return list.get(i).getActivityClass();
    }

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

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            ItemHomepageBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_homepage, viewGroup, false);
            convertView = binding.getRoot();
            convertView.setTag(binding);
        }
        HomeIcon item=list.get(i);
        ItemHomepageBinding binding = (ItemHomepageBinding) convertView.getTag();
        binding.setItem(item);

        binding.executePendingBindings();
        return convertView;
    }


}
