new method to build data in RecyclerView with Kotlin!
Click icon download lastest sample
Keyword: Data driven view 【数据驱动视图】
compile 'com.werb.moretype:moretype:$last_version'
or
implementation 'com.werb.moretype:moretype:$last_version'
- bug fix
- update MoreViewHolder Constructor
Keyword: Data driven view 【数据驱动视图】
data class SingleText(val title: String, val desc: String, val url: String)
or
class SingleText {
var title: String? = null
var desc: String? = null
var url: String? = null
}
// Register layoutID here or Register with adapter in Activity
@LayoutID(R.layout.item_view_single_type_one)
class SingleTypeOneViewHolder(values: MutableMap<String, Any>, containerView: View) : MoreViewHolder<SingleText>(containerView) {
override fun bindData(data: SingleText, payloads: List<Any>) {
title.text = data.title
desc.text = data.desc
icon.setImageURI(data.url)
}
}
import kotlinx.android.synthetic.main.activity_single_register.*
class SingleRegisterActivity: AppCompatActivity() {
private val adapter = MoreAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_single_register)
list.layoutManager = LinearLayoutManager(this)
/* register ViewHolder and attach to recyclerView */
adapter.apply {
// two method register Layout
register(RegisterItem(R.layout.item_view_single_type_one, SingleTypeOneViewHolder::class.java))
// or
register(SingleTypeOneViewHolder::class.java)
attachTo(single_register_list)
}
/* load any data List or model object */
adapter.loadData(DataServer.getSingleRegisterData())
}
}
Upon completion of these three steps, a list based on the [Data Driven View] has been completed.