Bindung in Recyclerview Adapter Android Java anzeigen
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;
}
}
}
Sudarshaana