当前位置:网站首页>Twenty-two, Kotlin advanced learning: simply learn RecyclerView to achieve list display;
Twenty-two, Kotlin advanced learning: simply learn RecyclerView to achieve list display;
2022-07-30 06:55:00 【¥Yiren alone drunk】
1. First add the RecyclerView dependency package
implementation 'androidx.recyclerview:recyclerview:1.1.0'2, item list

3, activity_main file;

4. Add list sub-layout file list_view;

5. Add the adapter class MyAdaptec.kt;
class MyAdapter(var context: Context,var items:List) : RecyclerView.Adapter() {// Bind the layout id hereclass ViewHolder(view: View): RecyclerView.ViewHolder(view) {val tv=view.findViewById(R.id.tv)}// bind child layoutoverride fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyAdapter.ViewHolder {val inflate = LayoutInflater.from(context).inflate(R.layout.list_view, parent, false)return ViewHolder(inflate)}// list display column numberoverride fun getItemCount(): Int =items.size// perform data assignmentoverride fun onBindViewHolder(holder: MyAdapter.ViewHolder, position: Int) {holder.tv.text=items.get(position)}} 6. MainActivity.kt
class MainActivity : AppCompatActivity() {lateinit var recyclerView: RecyclerViewoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)var items=ArrayList()for (item in 1..20){items.add("Kotlin learning"+item)}recyclerView=findViewById(R.id.recyclerView)recyclerView.adapter=MyAdapter(this,items)recyclerView.layoutManager=LinearLayoutManager(this)}} 7. Running effect;

边栏推荐
- Student management system
- uni-app: The use of uni-icons and how to customize icons
- C#中使用OleDb操作access数据库
- [Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app
- The most powerful and most commonly used SQL statements in history
- Monstache执行Monstache - f配置。toml出错不存在处理器类型和名称(附件)(= parse_exc类型
- The first WebAssembly program
- Flink CDC implements Postgres to MySQL streaming processing transmission case
- SSTI range
- C# WPF下限制TextBox只输入数字、小数点、删除等键
猜你喜欢

MYSQL一站式学习,看完即学完

Usage of exists in sql

Trust anchor for certification path not found.异常解决方法。

sql中 exists的用法

mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决

Detailed introduction to the usage of Nacos configuration center

Connect to Mysql in the cloud server Docker detailed graphic and text operations (full)

Arrays工具类的使用

国内数字藏品交易平台开发市场会开放二级市场吗

JDBC programming of MySQL database
随机推荐
FastAPI Quick Start
JVM Learning (2) Garbage Collector
TDengine集群搭建
C#中对委托的理解和使用
Flink PostgreSQL CDC configuration and FAQ
torch distributed training
sqli-labs less3/4 Targeting Notes
SQL Server安装教程
【数仓】数据仓库高频面试题题英文版(1)
MySQL 特殊语句及优化器
TDengineGUI无法连接TDengine
Mycat2.0 build tutorial
JVM学习(二) 垃圾收集器
史上超强最常用SQL语句大全
Awd summary
在线sql编辑查询工具sql-editor
Flink CDC 实现Postgres到MySQL流式加工传输案例
冒泡排序、选择排序、插入排序、快速排序
ClickHouse查询语句详解
Online sql editing query tool sql-editor