Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 15, 2023 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/2203a6c790997cf5c07ff6422d868ed1 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/2203a6c790997cf5c07ff6422d868ed1 to your computer and use it in GitHub Desktop.
How to use spinner
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// リスト項目を作成する
val data = mutableListOf<String>()
for (i in 1..5) {
data.add("項目$i")
}
// リスト項目をセットする
findViewById<Spinner>(R.id.spinner).adapter = ArrayAdapter(
this,
android.R.layout.simple_spinner_dropdown_item,
data
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment