1621613810772-2d40d03a-c9d7-4be3-a036-6214eba3b000[1].gif

    1. <me.luzhuo.lib_core.ui.recyclerview.EmptyRecyclerView
    2. android:id="@+id/rec"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent" />
    1. val itemAdapter = ItemAdapter()
    2. private fun initView() {
    3. rec.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
    4. rec.emptyAdapter = EmptyAdapter()
    5. rec.adapter = itemAdapter
    6. }
    7. fun notification(view: View) {
    8. itemAdapter.notifyDataSetChanged()
    9. }
    10. fun remove(view: View) {
    11. itemAdapter.removeData()
    12. itemAdapter.notifyItemRemoved(0)
    13. }
    14. fun add(view: View) {
    15. itemAdapter.addData()
    16. itemAdapter.notifyItemInserted(0)
    17. }

    EmptyAdapter 演示案例:

    实际使用中可添加点击刷新等操作

    1. class EmptyAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    2. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    3. return TitleHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_rec_empty, parent, false))
    4. }
    5. override fun getItemCount(): Int {
    6. return 1
    7. }
    8. override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { }
    9. inner class TitleHolder(item: View) : RecyclerView.ViewHolder(item) { }
    10. }