https://github.com/werbhelius/moretype
new method to build data in RecyclerView with Kotlin!
https://github.com/werbhelius/moretype
android kotlin kotlin-android kotlin-library recyclerview recyclerview-adapter recyclerview-item-animation recyclerview-multi-type viewtype
Last synced: about 2 months ago
JSON representation
new method to build data in RecyclerView with Kotlin!
- Host: GitHub
- URL: https://github.com/werbhelius/moretype
- Owner: werbhelius
- License: apache-2.0
- Created: 2017-07-02T10:40:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-12T10:49:43.000Z (over 5 years ago)
- Last Synced: 2025-03-23T23:35:57.385Z (2 months ago)
- Topics: android, kotlin, kotlin-android, kotlin-library, recyclerview, recyclerview-adapter, recyclerview-item-animation, recyclerview-multi-type, viewtype
- Language: Kotlin
- Homepage:
- Size: 1.03 MB
- Stars: 191
- Watchers: 7
- Forks: 19
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MoreType
> new method to build data in RecyclerView with Kotlin!
Click icon download lastest sample
[English](https://github.com/Werb/MoreType/blob/master/README_EN.md) | [中文版](https://github.com/Werb/MoreType/blob/master/README_ZH.md)
[](https://travis-ci.org/werbhelius/MoreType)
[](https://github.com/Werb/MoreType/blob/master/LICENSE)
[  ](https://bintray.com/werbhelius/maven/moretype/_latestVersion)
[](https://android-arsenal.com/api?level=16)**Keyword: Data driven view 【数据驱动视图】**
## Preview

## Dependency
```gradle
compile 'com.werb.moretype:moretype:$last_version'
```
or
```gradle
implementation 'com.werb.moretype:moretype:$last_version'
```## Update log
#### [v0.4.0](https://github.com/Werb/MoreType/releases/tag/v0.4.0)
* bug fix
* update MoreViewHolder Constructor## Usage
Keyword: Data driven view 【数据驱动视图】
#### Step 1. create a data model class, like:
```kotlin
data class SingleText(val title: String, val desc: String, val url: String)
```
or
```kotlin
class SingleText {
var title: String? = null
var desc: String? = null
var url: String? = null
}
```### Step 2. create a class (xxxViewHolder) extends abstract class `MoreViewHolder()` , like:
```kotlin
// Register layoutID here or Register with adapter in Activity
@LayoutID(R.layout.item_view_single_type_one)
class SingleTypeOneViewHolder(values: MutableMap, containerView: View) : MoreViewHolder(containerView) {override fun bindData(data: SingleText, payloads: List) {
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:
```kotlin
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.