当前位置:网站首页>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;
}
}
}
边栏推荐
- 最小生成树 Minimum Spanning Tree
- Local dealers play the community group purchase mode and share millions of operations
- The kth largest element in the [leetcode] array [215]
- 20220524_数据库过程_语句留档
- 成功改变splunk 默认URL root path
- antd组件upload上传xlsx文件,并读取文件内容
- Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
- [leetcode] there are duplicate elements [217]
- Application of containerization technology in embedded field
- Stop slave is stuck -- the event of the transaction is not copied completely
猜你喜欢

海思 VI接入视频流程

Loss function~

情感对话识别与生成简述

`Usage of ${}`

MySQL reset password, forget password, reset root password, reset MySQL password

Redis 过期策略+conf 记录

Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image

Hanging mirror security won four global infosec awards on rsac2022

Kubernetes uses the host name to allocate the pod on the specified node

Value sequence < detailed explanation of daily question >
随机推荐
Antd component upload uploads xlsx files and reads the contents of the files
中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
Chow-Liu Tree
Jerry's prototype will trigger shutdown after multiple touches [chapter]
严守工期,确保质量,这家AI数据标注公司做到了!
The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
Lc173. Binary search tree iterator
SQL进阶语法
阿里云有奖体验:如何使用 PolarDB-X
Local dealers play the community group purchase mode and share millions of operations
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
从2022年Q1财报看携程的韧性和远景
Minimum spanning tree
Generics and reflection, this is enough
Application of containerization technology in embedded field
剑指 Offer II 099. 最小路径之和-双百代码
Jerry's built-in shutdown current is 1.2ua, and then it can't be turned on by long pressing [chapter]
Qt QScrollArea