Skip to content

Latest commit

 

History

History
101 lines (74 loc) · 3.22 KB

README.md

File metadata and controls

101 lines (74 loc) · 3.22 KB

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

  • 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.