0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Android Studio】ListViewでリストを表示する方法【Kotlin】

Last updated at Posted at 2022-06-13
  • まずはListViewを追加します
<ListView
        android:id="@+id/countryList"
        android:layout_width="200dp"
        android:layout_height="500dp"
        app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName"
        app:layout_constraintLeft_toLeftOf="@+id/editTextTextPersonName"/>
  • 次にonCreateに下記を追加します
        // Listに表示する配列を用意する
        val countries = listOf("Brazil", "Indonesia", "Colombia");

        // Listに配置する
        var countryList = findViewById<ListView>(R.id.countryList)
        countryList.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries)
  • Emulaterで見てみると、配列内のデータが表示されていることが確認できます
1.png
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?