Why is the OnItemClickListener not being invoked and how can I store the selection?
I would like to create an autocomplete dropdown menu and then move to the next page the value saved but the listener doesn't show the text within that I wrote in the log.
Is there something missing? What should I add?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val countries = resources.getStringArray(R.array.countrylist)
val autoComp : AutoCompleteTextView = findViewById(id.autoComtv_SelectCountry)
val adapter = ArrayAdapter(this, R.layout.dropdown_countries, countries)
autoComp.setAdapter(adapter)
Log.d("hey", autoComp.text.toString())
AdapterView.OnItemClickListener {adapterView,view,i,l->
val itemSelected:String = adapterView.getItemAtPosition(i).toString()
Log.d("hey", "test") //doesn't show on console after picking country
Log.d("hey", autoComp.text.toString()) //doesn't show
Toast.makeText(this, "Item: $itemSelected", Toast.LENGTH_SHORT).show()
}
}
}