Kotlin RecyclerView + CardView use viewBinding #android studio #toturial
Kotlin RecyclerView + CardView use viewBinding
1. build.gradle (Module) add dependenciesset viewBinding true |
add implementation |
2. Create RecyclerViewActivity & activity_recycler_view.xml
use tools:listitem check UI Layout
3. check viewBinding file is create
check ActivityRecyclerViewBinding.java file is create |
if not find ActivityRecyclerViewBinding.file
Rebulid Project |
4. create stock_list_item.xml use cardView
5. Create StockAdapter use ViewBinding + RecyclerView
use ArrayList<Stock> to store information
in onBindViewHolder
use stockList[position] to setText in TextView
need to check stockList.size > 0, otherwise RecyclerVIew will not print data
6. Create Stock.kt to Store information
(2) prepare stockList
(3) set stocklist data to adapter
(4) set RecyclerView layoutManager
(5) notify data change
8. How to StartActivity -> RecyclerVIewActivity ?
GitHub Code : https://github.com/LiuPangYao/sidekotlin
project name : sidekotlin
commit version : 7a52839
more viewbinding describe : DataStore + ViewBinding
留言
張貼留言