Skip to content

Latest commit

 

History

History
78 lines (59 loc) · 2.53 KB

README_EN.md

File metadata and controls

78 lines (59 loc) · 2.53 KB

Flap

Build Status AndroidX RecyclerView API license Author PRs welcome


Usage

  1. Step1 : create a Model
  2. Step2 : create a layout file for component(A ViewHolder)
  3. Step3 : create a AdapterDelegate and register it.

1)Create a Model, lets say SimpleTextModel

data class SimpleTextModel(val content: String)

2)A simple layout that containers a TextView :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#0ff0ff"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:minHeight="50dp"
        android:paddingLeft="16dp"
        android:text="content"
        android:textColor="@android:color/white"
        android:textSize="16sp" />

</FrameLayout>

3)Create a AdapterDelegate by adapterDelegate DSL ,and
override onBind method:

val simpleTextDelegate = adapterDelegate<SimpleTextModel>(R.layout.flap_item_simple_text) {
    onBind { model ->
        bindTextView(R.id.tv_content) {
            text = model.content
        }
    }
}

Use a FlapAdapter instead of Adapter and register AdapterDelegate to a FlapAdapter: :

//create FlapAdapter
var adapter: FlapAdapter = FlapAdapter()

//register AdapterDelegate
adapter.registerAdapterDelegate(simpleTextDelegate)

val dataList = ArrayList<Any>()
dataList.add(SimpleTextModel("Android"))
dataList.add(SimpleTextModel("Java"))
dataList.add(SimpleTextModel("Kotlin"))

//setData
adapter.setDataAndNotify(dataList);

recyclerView.adapter = adapter

Here we go!!

License

Apache 2.0