• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

new method to build data in RecyclerView with Kotlin!

MoreType

new method to build data in RecyclerView with Kotlin!

download

Click icon download lastest sample

English | 中文版

Build Status Hex.pm Download API

Keyword: Data driven view 【数据驱动视图】

Preview

more-type-one more-type-two

Dependency

compile 'com.werb.moretype:moretype:$last_version'

or

implementation 'com.werb.moretype:moretype:$last_version'

Update log

v0.4.0

  • bug fix
  • update MoreViewHolder Constructor

Usage

Keyword: Data driven view 【数据驱动视图】

Step 1. create a data model class, like:

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
}

Step 2. create a class (xxxViewHolder) extends abstract class MoreViewHolder<T : Any>() , like:

// 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)
    }

}

Step 3. register and attach to recyclerview in Any where you build list, like:

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.