본문 바로가기
IT/Android

Kotlin] ListPreference 선택값 summary에 반영

by 깻잎쌈 2020. 4. 4.
반응형
val backgroundColorCategoryPref = findPreference("backgroundColorCategory") as ListPreference
// 선택값 summary에 반영
backgroundColorCategoryPref.setOnPreferenceChangeListener { preference, newValue ->
      if (preference is ListPreference) {
           val index = backgroundColorCategoryPref.findIndexOfValue(newValue.toString())
           backgroundColorCategoryPref.summary = backgroundColorCategoryPref.entries[index]
       }

      Log.d("선택한 배경색", backgroundColorCategoryPref.summary.toString())
      true
}

val backgroundColorCategoryPref = findPreference("backgroundColorCategory") as ListPreference

// 선택값 summary에 반영
backgroundColorCategoryPref.setOnPreferenceChangeListener { preference, newValue ->
      val index = backgroundColorCategoryPref.findIndexOfValue(newValue.toString())
      backgroundColorCategoryPref.summary = backgroundColorCategoryPref.entries[index]

      Log.d("선택한 배경색", backgroundColorCategoryPref.summary.toString())
      true
}
반응형

댓글