package tdc.edu.vn.test; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; public class CustomAdapter extends ArrayAdapter { Context context; int resource; ArrayList data; public CustomAdapter(Context context, int resource, ArrayList data) { super(context, resource); this.context = context; this.resource = resource; this.data = data; } @Override public int getCount() { return data.size(); } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = LayoutInflater.from(context).inflate(resource, null); TextView tvNationName = convertView.findViewById(R.id.tvNationName); TextView tvNationPopulation = convertView.findViewById(R.id.tvNationPopulation); ImageView ivNationImage = convertView.findViewById(R.id.ivNationImage); Nation nation = data.get(position); tvNationName.setText(nation.getName()); tvNationPopulation.setText(nation.getPopulation()); ivNationImage.setImageResource(nation.getFlag()); return convertView; } }