@@ -5,10 +5,7 @@ import android.os.Bundle
5
5
import android.support.v7.widget.LinearLayoutManager
6
6
import android.util.SparseArray
7
7
import android.widget.Toast
8
- import k.lhl.adapter.Adapter
9
- import k.lhl.adapter.MultiRecyclerAdapter
10
- import k.lhl.adapter.RecyclerAdapter
11
- import k.lhl.adapter.positon
8
+ import k.lhl.adapter.*
12
9
import kotlinx.android.synthetic.main.activity_main.*
13
10
import kotlinx.android.synthetic.main.item_test.view.*
14
11
@@ -18,62 +15,88 @@ class MainActivity : AppCompatActivity() {
18
15
super .onCreate(savedInstanceState)
19
16
setContentView(R .layout.activity_main)
20
17
21
- val data = mutableListOf<String >()
22
- for (i in 0 .. 10 ) {
23
- data.add(i.toString())
24
- }
18
+ // val data = mutableListOf<String>()
19
+ // for (i in 10..30 ) {
20
+ // data.add(i.toString())
21
+ // }
25
22
//
26
23
// recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL }
27
- //
28
- // recyList.adapter = RecyclerAdapter(data, R.layout.item_test) { item, position ->
29
- // tvNum.text = item
24
+ // recyList.adapter = RecyclerAdapter(data, R.layout.item_test) {
25
+ // tvNum.text = it
30
26
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() }
31
27
// }.setOnItemClickListener {
32
- // Toast.makeText(this@MainActivity, "点击 $position", Toast.LENGTH_SHORT).show()
28
+ // Toast.makeText(this@MainActivity, "点击 $position $it ", Toast.LENGTH_SHORT).show()
33
29
// }.setOnItemLongClickListener {
34
- // Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show()
30
+ // Toast.makeText(this@MainActivity, "长按 $position $it ", Toast.LENGTH_SHORT).show()
35
31
// }
36
32
37
33
//
38
- lvList.adapter = Adapter (data, R .layout.item_test) {
39
- tvNum.text = this .item
40
- btn.setOnClickListener { Toast .makeText(this @MainActivity, " 点击" + item, Toast .LENGTH_SHORT ).show() }
41
- }
42
-
43
- // val data = mutableListOf<Pair<Int, String>>()
44
- // for (i in 1..20) {
45
- // if (i < 4)
46
- // data.add(Pair(0, i.toString()))
47
- // else
48
- // data.add(Pair(1, i.toString()))
49
- // }
50
34
//
51
- // recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL }
52
- // recyList.adapter = MultiRecyclerAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { item, position ->
53
- // tvNum.text = item
35
+ // lvList.adapter = Adapter(data, R.layout.item_test) {
36
+ // tvNum.text = it
54
37
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() }
38
+ // }
39
+
40
+ val data = mutableListOf<Pair <Int , String >>()
41
+ for (i in 10 .. 30 ) {
42
+ if (i < 14 || i > 28 )
43
+ data.add(Pair (0 , i.toString()))
44
+ else
45
+ data.add(Pair (1 , i.toString()))
46
+ }
47
+
48
+ recyList.layoutManager = LinearLayoutManager (this ).apply { orientation = LinearLayoutManager .VERTICAL }
49
+ recyList.adapter = MultiRecyclerAdapter (data, SparseArray <Int >().apply { put(0 , R .layout.item_test);put(1 , R .layout.item_test_2) }) {
50
+ when (type) {
51
+ 0 -> {
52
+ tvNum.text = it
53
+ btn.setOnClickListener { Toast .makeText(this @MainActivity, " 点击类型1 $position " , Toast .LENGTH_SHORT ).show() }
54
+ }
55
+ 1 -> {
56
+ tvNum.text = it
57
+ btn.setOnClickListener { Toast .makeText(this @MainActivity, " 点击类型2 $position " , Toast .LENGTH_SHORT ).show() }
58
+ }
59
+ }
60
+ }.setOnItemClickListener {
61
+ Toast .makeText(this @MainActivity, " 点击 $position $it " , Toast .LENGTH_SHORT ).show()
62
+ }.setOnItemLongClickListener {
63
+ Toast .makeText(this @MainActivity, " 长按 $position $it " , Toast .LENGTH_SHORT ).show()
64
+ }
65
+
66
+ // recyList.adapter = MulRecyclerAdapter(data, 0, R.layout.item_test) {
67
+ // tvNum.text = it
68
+ // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型1 $position", Toast.LENGTH_SHORT).show() }
69
+ // }.addItemType(1, R.layout.item_test_2) {
70
+ // tvNum.text = it
71
+ // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型2 $position", Toast.LENGTH_SHORT).show() }
55
72
// }.setOnItemClickListener {
56
- // Toast.makeText(this@MainActivity, "点击 $item ", Toast.LENGTH_SHORT).show()
73
+ // Toast.makeText(this@MainActivity, "点击 $position $it ", Toast.LENGTH_SHORT).show()
57
74
// }.setOnItemLongClickListener {
58
- // Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show()
75
+ // Toast.makeText(this@MainActivity, "长按 $position $it ", Toast.LENGTH_SHORT).show()
59
76
// }
60
77
61
78
62
- //
63
- //
64
- // lvList.adapter = MultiAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { type, item, position ->
79
+ // lvList.adapter = MultiAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) {
65
80
// when (type) {
66
81
// 0 -> {
67
- // tvNum.text = "$item 类型0"
82
+ // tvNum.text = "$it 类型0"
68
83
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型0", Toast.LENGTH_SHORT).show() }
69
84
// }
70
85
// 1 -> {
71
- // tvNum.text = "$item 类型1"
86
+ // tvNum.text = "$it 类型1"
72
87
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() }
73
88
// }
74
89
// }
75
90
// }
76
91
92
+ // lvList.adapter = MulAdapter(data, 0, R.layout.item_test) {
93
+ // tvNum.text = "$it 类型1"
94
+ // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() }
95
+ // }.addItemType(1, R.layout.item_test_2) {
96
+ // tvNum.text = "$it 类型2"
97
+ // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型2", Toast.LENGTH_SHORT).show() }
98
+ // }
99
+
77
100
78
101
}
79
102
}
0 commit comments