当前位置:网站首页>Use of recyclerview with viewbinding
Use of recyclerview with viewbinding
2022-07-02 23:07:00 【Automatic 2004 haojinhui】
RecyclerView combination ViewBinding Use
introduce ViewBinding

android {
compileSdk 32
defaultConfig {
... ...
viewBinding {
enabled = true
}
}
add to Adapter Sub layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#D05C5C" android:orientation="vertical" android:padding="16dp">
<TextView android:id="@+id/main_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" Xiao Wang " />
<TextView android:id="@+id/main_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="123543123" />
</LinearLayout>
RecyclerViewAdapter Realization

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.recyclerview.databinding.ViewMainBinding;
import java.util.List;
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MainViewHolder> {
private static final String TAG = "MainAdapter";
private List<String> mList;
@SuppressLint("NotifyDataSetChanged")
public void setList(List<String> list) {
mList = list;
Log.e(TAG, "setList: " + mList);
notifyDataSetChanged();
}
@NonNull
@Override
public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewMainBinding binding = ViewMainBinding
.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new MainViewHolder(binding);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
holder.binding.mainName.setText(" Xiao Ming : " + position);
holder.binding.mainPhone.setText(String.valueOf(position * 31321));
}
@Override
public int getItemCount() {
return mList == null ? 0 : mList.size();
}
static class MainViewHolder extends RecyclerView.ViewHolder {
final ViewMainBinding binding;
MainViewHolder(ViewMainBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}
边栏推荐
- 从2022年Q1财报看携程的韧性和远景
- Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
- Introduction to the latest plan of horizon in April 2022
- RecyclerView结合ViewBinding的使用
- Array advanced improvement
- Brief introduction of emotional dialogue recognition and generation
- [leetcode] there are duplicate elements [217]
- Motivation du Protocole de chiffrement avancé AES
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- Odoo13 build a hospital HRP environment (detailed steps)
猜你喜欢

Niuke network: maximum submatrix

从2022年Q1财报看携程的韧性和远景

AES高级加密协议的动机阐述

Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises

归并排序详解及应用

Boot actuator - Prometheus use

成功改变splunk 默认URL root path

設置單擊右鍵可以選擇用VS Code打開文件
![[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM](/img/5d/c23ec16df6ce8d78207b635f59dc20.png)
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM

Jatpack------LiveData
随机推荐
[Luogu p1541] tortoise chess [DP]
Editor Caton
Successfully changed Splunk default URL root path
深度剖析数据在内存中的存储----C语言篇
Introduction and response to high concurrency
泛型与反射,看这篇就够了
Go语言sqlx库操作SQLite3数据库增删改查
MySQL queries nearby data And sort by distance
Chow-Liu Tree
Introduction to the latest plan of horizon in April 2022
QT qpprogressbar details
最小生成树 Minimum Spanning Tree
Pytorch training CPU usage continues to grow (Bug)
RecyclerView结合ViewBinding的使用
P7072 [CSP-J2020] 直播获奖
MySQL查询附近的数据.并按距离进行排序.
antd组件upload上传xlsx文件,并读取文件内容
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
PMP project integration management
Qt QScrollArea