Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created March 13, 2022 10:15
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/9dac4fec21c03702aea450a5da1ed832 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/9dac4fec21c03702aea450a5da1ed832 to your computer and use it in GitHub Desktop.
【Kotlin】ListView with one textview 6
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val data = mutableListOf(
"とり", "しか", "ぞう", "きつね",
"かば", "ライオン", "パンダ", "ひつじ"
)
val list = findViewById<ListView>(R.id.list)
val adapter = ArrayAdapter(
this,
android.R.layout.simple_list_item_1,
data
)
list.adapter = adapter
list.setOnItemClickListener { adapterView, view, position, id ->
adapter.add("犬")
adapter.remove("ライオン")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment