-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPagingActivity.kt
36 lines (30 loc) · 1.14 KB
/
PagingActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.ocnyang.recyclerviewevent.paging3
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ocnyang.recyclerviewevent.R
class PagingActivity : AppCompatActivity() {
private lateinit var mAdapter: PagingAdapter
private val viewModel by lazy {
ViewModelProvider(this, PagingViewModelFactory()).get(
PagingViewModel::class.java
)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_paging)
findViewById<RecyclerView>(R.id.recyclerView).apply {
layoutManager = LinearLayoutManager(context)
mAdapter = PagingAdapter(context)
adapter = mAdapter.withLoadStateHeaderAndFooter(
header = PagingLoadStateAdapter(context),
footer = PagingLoadStateAdapter(context)
)
}
viewModel.requestFruit("苹果") {
mAdapter.submitData(it)
}
}
}