Skip to content

Using ListView to display a list(Kotlin)

   

Use ListView to display the list. Kotlin and Android are difficult because of the large number of configuration files.

alt

<?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>
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
}
}
view raw MainActivity.kt hosted with ❤ by GitHub

  1. Setting Icons in AndroidStudio
  2. Changing the color of the BottomNavigationView when switching
  3. Implementing BottomNavigation with nested Fragments.
  4. Creating a Tab with ListView in Kotlin
  5. Obtaining the current time(kotlin)
  6. Shadowing the action bar in Android apps
  7. Changing the Android app status bar