0101011001010111

android.R.layout.simple_list_item_1 본문

Kotlin/[스스로]Kotlin&안드로이드

android.R.layout.simple_list_item_1

[진주] 2023. 8. 24. 05:28
728x90
반응형

android.R.layout.simple_list_item_1

package com.example.simplelistviewtest

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import com.example.simplelistviewtest.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        //데이터 원본 (대충 막 작성했음)
        val items = arrayOf<String>("item1","item2","item3","item1","item2","item3","item1","item2","item3","item1","item2","item3","item1","item2","item3","item1","item2","item3","item1","item2","item3")

        //어댑터 준비! 이번에는 ArrayAdapter를 써볼것이다!
        val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, items)

        //어댑터 연결해주기
        binding.myListView.adapter = adapter
    }
}

 

 

xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/myListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형