Use ListView to display the list. Kotlin and Android are difficult because of the large number of configuration files.
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<ListView | |
android:id="@+id/listView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> | |
</android.support.constraint.ConstraintLayout> |
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
package swiswiswift.com.swiswiswiftandroid | |
import android.support.v7.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.ArrayAdapter | |
import android.widget.ListView | |
class MainActivity : AppCompatActivity() { | |
private var listView: ListView? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val titles = arrayListOf( | |
"Mac", | |
"Apple", | |
"Mini", | |
"iMac", | |
"Pro", | |
"Apple", | |
"Mini", | |
"iMac", | |
"iPhone", | |
"Watch", | |
"Google Home", | |
"Alexa", | |
"Pro" | |
) | |
this.listView = findViewById(R.id.listView) | |
val adapter = ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, titles) | |
listView!!.adapter = adapter | |
} | |
} |