Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

view binding in recyclerview adapter android java

package com.jbws.myviewbindingdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jbws.myviewbindingdemo.databinding.RowXmlViewBinding;
import com.jbws.myviewbindingdemo.pojo.ModelObject;

import java.util.ArrayList;

public class RecyclerViewListAdapter extends RecyclerView.Adapter<RecyclerViewListAdapter.ViewHolder> {
    public ArrayList<ModelObject> modelObjectArrayList;

    public RecyclerViewListAdapter(ArrayList<ModelObject> modelObjectArrayList) {
        this.modelObjectArrayList = modelObjectArrayList;
    }

    @NonNull
    @Override
    public RecyclerViewListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(RowXmlViewBinding.inflate(LayoutInflater.from(parent.getContext()),
                parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewListAdapter.ViewHolder holder, final int position) {
        ModelObject modelObject = modelObjectArrayList.get(position);
        holder.rowXmlViewBinding.txtObjectName.setText(modelObject.getFullName());
        holder.rowXmlViewBinding.btnUpdateName.setOnClickListener(view -> {
         Log.i("LOG_TAG", "Full Name: " + modelObject.getFullName);
        });
    }

    @Override
    public int getItemCount() {
        return modelObjectArrayList == null ? 0 :
                modelObjectArrayList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private RowXmlViewBinding rowXmlViewBinding;

        public ViewHolder(RowXmlViewBinding rowXmlViewBinding) {
            super(rowXmlViewBinding.getRoot());
            this.rowXmlViewBinding = rowXmlViewBinding;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: JAVA HashMap get keys by values 
Java :: map interation in java 
Java :: convert fahrenheit to celsius 
Java :: java read keyboard input 
Java :: entity cannot be resolved to a type in spring boot eclipse 
Java :: how to add input in array java 
Java :: java create list integer range 
Java :: how to change color of progress bar in android 
Java :: java get year month day hour minute second 
Java :: java 8 find in list by property 
Java :: java read directory 
Java :: java how to make a number 
Java :: java remove duplicates 
Java :: keytool error: java.io.FileNotFoundException: my-release-key.keystore (Access is denied) java.io.FileNotFoundException: my-release-key.keystore (Access is denied) 
Java :: java return tuple 
Java :: junit vintage engine maven 
Java :: java get bigger int 
Java :: get preference value android 
Java :: add opacity to activity android 
Java :: java string to float 
Java :: java eclipse console clear 
Java :: milliseconds to seconds java 
Java :: main method 
Java :: convert javascritp getTime() to datetime 
Java :: android application class manifest 
Java :: android @Parcelize not resolving 
Java :: java solid principles 
Java :: AndroidManifest.xml could not be found. 
Java :: java scan a file 
Java :: how to take max value from priority queue in java 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =