I have problem with code i am using spinner in my application when clicking spinner item its go to new activity when backpress the values of spinner not reset i want to reset the values of spinner when back press help me please
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
if (parent?.getItemAtPosition(position)?.equals("Select branch")!!){
}
if(position==1){
val aryadpt=ArrayAdapter(this@Syllabus,R.layout.text_layout,fsem)
spin.adapter=aryadpt
spin.onItemSelectedListener= object :AdapterView.OnItemSelectedListener{
override fun onNothingSelected(parent: AdapterView<*>?) {
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
when(position){
1-> btn.setOnClickListener { startActivity(Intent(this@Syllabus,First_sem::class.java))
}
2-> btn.setOnClickListener { startActivity(Intent(this@Syllabus,Second_sem::class.java)) }
}}
}
}
Simply reset the selection before navigating to the new Activity
spin.setSelection(-1)
//startActivity(...)
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.