-
-
Save codeforfun-jp/4b5deff9ff26951ee30db00c02617cac to your computer and use it in GitHub Desktop.
How to use spinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), OnItemSelectedListener { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById<Spinner>(R.id.spinner).onItemSelectedListener = this | |
} | |
// 項目が選択された場合 | |
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | |
Toast.makeText(this, "${parent?.selectedItem}が選択されました", Toast.LENGTH_SHORT).show() | |
} | |
// 項目が選択されなかった場合 | |
override fun onNothingSelected(parent: AdapterView<*>?) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment