当前位置:网站首页>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;

边栏推荐
- npm安装和npm安装——保存
- CTFSHOW command execution [web29-web124] unfinished to be continued
- JVM学习(二) 垃圾收集器
- phpok website vulnerability exploitation analysis
- Extraction of BaseDAO
- 【数仓】数据质量
- oracle row to column, column to row summary
- sqli-labs shooting range SQL injection learning Less-1
- C# WPF中监听窗口大小变化事件
- 第一个WebAssembly程序
猜你喜欢

Servlet基本原理与常见API方法的应用

SQL Server 数据库之生成与执行 SQL 脚本

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

【数仓】数据仓库高频面试题题英文版(1)

oracle row to column, column to row summary

Competition WP in May

Powerhouse Cup Preliminary WP

Use kotlin to extend plugins/dependencies to simplify code (after the latest version 4.0, this plugin has been deprecated, so please choose to learn, mainly to understand.)

TDengine cluster construction

JDBC programming of MySQL database
随机推荐
The number of warehouse 】 data quality
SQL Server database generation and execution of SQL scripts
Jackson 序列化失败问题-oracle数据返回类型找不到对应的Serializer
Flink CDC 实现Postgres到MySQL流式加工传输案例
c#下Web3合约空投、转账调用代码
misc-file steganography of CTF
在不同的服务器上基于docker部署redis主从同步
Detailed explanation of ClickHouse query statement
学生成绩管理系统(C语言版)
Redis 客户端常见异常分析
MySQL 5.7 installation tutorial (all steps, nanny tutorials)
第一个WebAssembly程序
二十二、Kotlin进阶学习:简单学习RecyclerView实现列表展示;
JVM学习(二) 垃圾收集器
oracle row to column, column to row summary
C#利用开源NPlot实现K线图(蜡烛图)
Briefly describe SSRF
Flink-流/批/OLAP一体得到Flink引擎
uni-app: about custom components, easycom specs, uni_modules, etc.
学生管理系统