简体   繁体   中英

How to handle the selected item in AutoCompleteTextView dropdown in kotlin?

I have a dropdown list in a fragment that I would like to get the item selected and work with it. How can I achieve this?

       val states = resources.getStringArray(R.array.states)
        val arrayAdapter = ArrayAdapter(requireContext(), R.layout.state_drop_down_item, states)
        binding.addAddressFragmentStateAutoComplete.setAdapter(arrayAdapter)

To get the selected item of AutoCompleteTextView dropdown you have to set onItemClickListener to AutoCompleteTextView like below:

addAddressFragmentStateAutoComplete.onItemClickListener = OnItemClickListener { parent, view, position, id ->
    val item = parent.getItemAtPosition(position).toString()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM