I'm making android app using kotlin at first time, I want to ask u guys why 'spinnerType.onItemSelectedListener' this line in error .
this is my AddActivity.kt.
override fun onCreate(savedInstanceState: Bundle?) {
spinnerType = findViewById(R.id.spinner_type)
spinnerCategory = findViewById(R.id.spinner_category)
editTextAmount = findViewById(R.id.edit_text_amount)
editTextNote = findViewById(R.id.edit_text_note)
// binding adapter and listener
expendCategoryList = object : ArrayList<String>() {
init {
add("aaa")
add("bbb")
add("ccc")
}
}
incomeCategoryList = object : ArrayList<String>() {
init {
add("dd")
add("ee")
}
}
bindSpinnerCategoryData(true)
// bind event listener about spinnerType
spinnerType.onItemSelectedListener
}
private fun bindSpinnerCategoryData(isExpend: Boolean) {
val arrayAdapter: ArrayAdapter<String>
val targetList = if (isExpend) expendCategoryList else incomeCategoryList
val list = ArrayList(targetList)
list.add("add new category...")
arrayAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, list)
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// new data adpater binding aboutspinnerCategory
spinnerCategory.setAdapter(arrayAdapter)
}