File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
lite/src/main/java/com/pengxh/kt/lite/adapter Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com.pengxh.kt.lite.adapter
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.view.LayoutInflater
4
5
import android.view.ViewGroup
5
6
import androidx.annotation.LayoutRes
@@ -9,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
9
10
* RecyclerView多选适配器
10
11
*/
11
12
abstract class MultipleChoiceAdapter <T >(
12
- @LayoutRes private val xmlResource : Int , private val dataRows : List <T >
13
+ @LayoutRes private val xmlResource : Int , private val dataRows : MutableList <T >
13
14
) : RecyclerView.Adapter<ViewHolder>() {
14
15
15
16
private val kTag = " MultipleChoiceAdapter"
@@ -41,6 +42,18 @@ abstract class MultipleChoiceAdapter<T>(
41
42
}
42
43
}
43
44
45
+ @SuppressLint(" NotifyDataSetChanged" )
46
+ fun setRefreshData (dataRows : MutableList <T >) {
47
+ this .dataRows.clear()
48
+ this .dataRows.addAll(dataRows)
49
+ notifyDataSetChanged()
50
+ }
51
+
52
+ fun setLoadMoreData (dataRows : MutableList <T >) {
53
+ this .dataRows.addAll(dataRows)
54
+ notifyItemRangeInserted(this .dataRows.size, dataRows.size)
55
+ }
56
+
44
57
abstract fun convertView (viewHolder : ViewHolder , position : Int , item : T )
45
58
46
59
private var itemCheckedListener: OnItemCheckedListener <T >? = null
Original file line number Diff line number Diff line change 1
1
package com.pengxh.kt.lite.adapter
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.view.LayoutInflater
4
5
import android.view.ViewGroup
5
6
import androidx.annotation.LayoutRes
@@ -10,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
10
11
* RecyclerView普通列表适配器
11
12
*/
12
13
abstract class NormalRecyclerAdapter <T >(
13
- @LayoutRes private val xmlResource : Int , private val dataRows : List <T >
14
+ @LayoutRes private val xmlResource : Int , private val dataRows : MutableList <T >
14
15
) : RecyclerView.Adapter<ViewHolder>() {
15
16
16
17
private val kTag = " NormalRecyclerAdapter"
@@ -28,6 +29,18 @@ abstract class NormalRecyclerAdapter<T>(
28
29
}
29
30
}
30
31
32
+ @SuppressLint(" NotifyDataSetChanged" )
33
+ fun setRefreshData (dataRows : MutableList <T >) {
34
+ this .dataRows.clear()
35
+ this .dataRows.addAll(dataRows)
36
+ notifyDataSetChanged()
37
+ }
38
+
39
+ fun setLoadMoreData (dataRows : MutableList <T >) {
40
+ this .dataRows.addAll(dataRows)
41
+ notifyItemRangeInserted(this .dataRows.size, dataRows.size)
42
+ }
43
+
31
44
abstract fun convertView (viewHolder : ViewHolder , position : Int , item : T )
32
45
33
46
private var itemClickedListener: OnItemClickedListener <T >? = null
Original file line number Diff line number Diff line change 1
1
package com.pengxh.kt.lite.adapter
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.view.LayoutInflater
4
5
import android.view.ViewGroup
5
6
import androidx.annotation.LayoutRes
@@ -10,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
10
11
* RecyclerView单选适配器
11
12
*/
12
13
abstract class SingleChoiceAdapter <T >(
13
- @LayoutRes private val xmlResource : Int , private val dataRows : List <T >
14
+ @LayoutRes private val xmlResource : Int , private val dataRows : MutableList <T >
14
15
) : RecyclerView.Adapter<ViewHolder>() {
15
16
16
17
private val kTag = " SingleChoiceAdapter"
@@ -43,6 +44,18 @@ abstract class SingleChoiceAdapter<T>(
43
44
}
44
45
}
45
46
47
+ @SuppressLint(" NotifyDataSetChanged" )
48
+ fun setRefreshData (dataRows : MutableList <T >) {
49
+ this .dataRows.clear()
50
+ this .dataRows.addAll(dataRows)
51
+ notifyDataSetChanged()
52
+ }
53
+
54
+ fun setLoadMoreData (dataRows : MutableList <T >) {
55
+ this .dataRows.addAll(dataRows)
56
+ notifyItemRangeInserted(this .dataRows.size, dataRows.size)
57
+ }
58
+
46
59
abstract fun convertView (viewHolder : ViewHolder , position : Int , item : T )
47
60
48
61
private var itemCheckedListener: OnItemCheckedListener <T >? = null
You can’t perform that action at this time.
0 commit comments