Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- lifecycle
- Algorithm
- CollapsingToolbarLayout
- onLayout
- 알고리즘
- recyclerview
- Android
- onMeasure
- activity
- sqlite
- DataBinding
- AppBarLayout
- HTTP
- kotlin
- LiveData
- 코틀린
- View
- 알림
- CoordinatorLayout
- 백준
- hilt
- BOJ
- Behavior
- Navigation
- notification
- room
- CustomView
- Coroutine
- ViewModel
- 안드로이드
Archives
- Today
- Total
개발일지
Android in A..Z - RecyclerView (Selection - Predicate) 본문
Android (안드로이드)/RecyclerView
Android in A..Z - RecyclerView (Selection - Predicate)
강태종 2021. 1. 15. 04:29SelectionPredicate
Select를 좀 더 디테일하게 설정할 수 있다.(하나만 선택, 여러개 선택, ViewHolder에 따른 조건적 선택)
- SelectionPredicates.createSelectAnything() : 아무거나 여러개 선택가능
- SelectionPredicates.createSelectSingleAnything() : 아무거나 한개만 선택가능
SelectionTracker.SelectionPredicate를 상속받아서 구현
ViewHolder에 YES만 선택되게한 예제
class SelectionPredicate(private val recyclerView: RecyclerView) : SelectionTracker.SelectionPredicate<Long>() {
override fun canSetStateForKey(key: Long, nextState: Boolean): Boolean {
val holder = recyclerView.findViewHolderForItemId(key)
return if (holder is SelectionAdapter.SelectionHolder) {
holder.element.text == "YES"
} else {
false
}
}
override fun canSetStateAtPosition(position: Int, nextState: Boolean): Boolean {
return true
}
override fun canSelectMultiple(): Boolean {
return true
}
}
- canSetStateForKey(key, nextState) : key는 Id, nextState는 선택 상태이다. Id에 따른 선택가능 여부를 정한다.
- canSetStateAtposition : position에 따른 선택가능 여부를 정한다.
- canSelectMultiple : 복수 선택가능 여부를 정한다.
Git (예제코드)
github.com/KangTaeJong98/Example/tree/main/Android/RecyclerView
KangTaeJong98/Example
My Example Code. Contribute to KangTaeJong98/Example development by creating an account on GitHub.
github.com
'Android (안드로이드) > RecyclerView' 카테고리의 다른 글
Android in A..Z - RecyclerView (SnapHelper) (0) | 2021.01.21 |
---|---|
Android in A..Z - RecyclerView (Selection - Observer) (0) | 2021.01.15 |
Android in A..Z - RecyclerView (Selection Tracker) (0) | 2021.01.15 |
Android in A..Z - RecyclerView (payload) (0) | 2021.01.10 |
Android in A..Z - RecyclerView (setHasFixedSize) (1) | 2021.01.10 |
Comments