1、首先,确保您已经添加了BaseQuickAdapter和RecyclerView的依赖项。您可以在项目的build.gradle文件中添加以下依赖项:
dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
}
2、创建一个数据模型类来表示每个列表项的数据。例如,假设您有一个名为Item的数据类:
public class Item {
private String name;
private boolean isSelected;
public Item(String name) {
this.name = name;
this.isSelected = false;
}
public String getName() {
return name;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
}
3、创建一个Adapter类,继承自BaseQuickAdapter<Item, BaseViewHolder>。在Adapter中,您需要处理单选逻辑以及默认选择第一个项的逻辑:
public class ItemAdapter extends Ba