<me.luzhuo.lib_core.ui.recyclerview.EmptyRecyclerView
android:id="@+id/rec"
android:layout_width="match_parent"
android:layout_height="match_parent" />
val itemAdapter = ItemAdapter()
private fun initView() {
rec.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
rec.emptyAdapter = EmptyAdapter()
rec.adapter = itemAdapter
}
fun notification(view: View) {
itemAdapter.notifyDataSetChanged()
}
fun remove(view: View) {
itemAdapter.removeData()
itemAdapter.notifyItemRemoved(0)
}
fun add(view: View) {
itemAdapter.addData()
itemAdapter.notifyItemInserted(0)
}
EmptyAdapter 演示案例:
实际使用中可添加点击刷新等操作
class EmptyAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return TitleHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_rec_empty, parent, false))
}
override fun getItemCount(): Int {
return 1
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { }
inner class TitleHolder(item: View) : RecyclerView.ViewHolder(item) { }
}