반응형
// 아이템 배열
val items = ArrayList<String>()
// 어댑터 생성 및 설정
val adapter by lazy { ArrayAdapter(this, android.R.layout.imple_list_item_multiple_choice, items) }
listView.adapter = adapter
listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE
...
// 선택된 아이템들 삭제버튼
deleteListButton.setOnClickListener {
val checkedItems = listView.checkedItemPositions
for (i in adapter.count - 1 downTo 0) {
if (checkedItems.get(i)) {
Log.d("선택된 아이템 삭제", i.toString())
items.removeAt(i)
}
}
adapter.notifyDataSetChanged()
// 선택 초기화
listView.clearChoices()
}
반응형
'IT > Android' 카테고리의 다른 글
Kotlin] 안드로이드 알람 설정 & 해제 (0) | 2020.03.29 |
---|---|
Kotlin] 안드로이드 당겨서 새로고침 // SwipeRefreshLayout (0) | 2020.03.20 |
Kotlin] 안드로이드 리스트뷰 삭제 (단일선택) (0) | 2020.03.18 |
Kotlin] 안드로이드 토스트 메세지 위치 // 중앙으로 (0) | 2020.03.18 |
Kotlin] 안드로이드 스레드 만들기 (0) | 2020.03.17 |
댓글