I trying to display a set of values using RecyclerView, I'm trying to use data binding , however RecyclerView is showing no item and its empty.

If I dont use Databinding, code will work fine and Recycerview is displaying the items.

Below is Adapter Class

public class ParticipantsAdapter extends RecyclerView.Adapter<ParticipantsAdapter.ParticipantsViewHolder> {

    ArrayList nameList,iconList;


    public ParticipantsAdapter(ArrayList name, ArrayList iconList) {

        this.nameList = name;
        this.iconList = iconList;
    }

    @NonNull
    @Override
    public ParticipantsAdapter.ParticipantsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {


        ParticpantItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()),R.layout.particpant_item,null,false);
        return new ParticipantsViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull 
         ParticipantsAdapter.ParticipantsViewHolder participantsViewHolder, int i) {

          participantsViewHolder.bindTo(i);
    }

    @Override
    public int getItemCount() {
        return nameList.size();
    }

    class ParticipantsViewHolder extends RecyclerView.ViewHolder {
        private ParticpantItemBinding binding;
        TextView name;
        ImageView icon;

        public ParticipantsViewHolder(ParticpantItemBinding view) {
            super(view.getRoot());
            this.binding = view;
            this.binding.executePendingBindings();

        }

        private void bindTo(int pos) {
            binding.tvName.setText(nameList.get(pos)+"");
            binding.ivAvtar.setImageResource((int)iconList.get(pos));
            binding.executePendingBindings();
        }
    }

0 Answers