File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed
app/src/main/java/com/dylanc/viewbinding/sample Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -33,16 +33,7 @@ class MainActivity : AppCompatActivity() {
33
33
private val binding by binding(ActivityMainBinding ::inflate)
34
34
private val loadingDialog by lazy { LoadingDialogFragment () }
35
35
private val handler = Handler (Looper .getMainLooper())
36
- private val listAdapter = ListAdapter <Foo , ItemFooBinding >(DiffCallback ()) {
37
- with (binding) {
38
- tvFoo.text = it.value
39
- }
40
- }
41
- private val list = listOf (
42
- Foo (" item 1" ),
43
- Foo (" item 2" ),
44
- Foo (" item 3" )
45
- )
36
+ private val list = listOf (Foo (" item 1" ), Foo (" item 2" ), Foo (" item 3" ))
46
37
47
38
override fun onCreate (savedInstanceState : Bundle ? ) {
48
39
super .onCreate(savedInstanceState)
@@ -53,11 +44,15 @@ class MainActivity : AppCompatActivity() {
53
44
loadingDialog.dismiss()
54
45
}, 2000 )
55
46
}
56
- recyclerView.adapter = listAdapter
57
- listAdapter .submitList(list)
47
+ recyclerView.adapter = adapter
48
+ adapter .submitList(list)
58
49
}
59
50
}
60
51
52
+ private val adapter = ListAdapter <Foo , ItemFooBinding >(DiffCallback ()) {
53
+ binding.tvFoo.text = it.value
54
+ }
55
+
61
56
class DiffCallback : DiffUtil .ItemCallback <Foo >() {
62
57
override fun areItemsTheSame (oldItem : Foo , newItem : Foo ) = oldItem.value == newItem.value
63
58
override fun areContentsTheSame (oldItem : Foo , newItem : Foo ) = oldItem.value == newItem.value
You can’t perform that action at this time.
0 commit comments