개발 창고/Android

[Android] How to use ArrayAdapter in ListView

로이제로 2024. 2. 27. 08:00
반응형

 When developing Android applications, they often use ListView.

 

 Whether it's the web or mobile, the bulletin board type is the most popular function that users want. (If you personalize the bulletin board well, it's very useful.)

 

 In the case of the web screen, the horizontal screen of the PC was specialized, and the table form was dominated.

 As we move to the mobile environment, existing PC generation users often want table-type posts,

 

 With the transition to a mobile environment, existing PC generation users often want a table-type post, but in fact, because the mobile phone is in portrait mode, it often does not satisfy the needs of users.

 

 The beginning was a bit long, and I often use ListView to show you a list of these posts (and, of course, I've been using PagerViewer, which is more functional lately)

The form of the default ListView


EXAMPLE

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)

        // List date to show in list view (for testing)
        // List date to show in list view (for testing)
        val list = ArrayList<String>()
        list.add("ITEM01")
        list.add("ITEM02")
        list.add("ITEM03")
        list.add("ITEM04")

        // STEP01. Declare the list view of the layout as a ListView called mlistview.

        // STEP01. Declare the list view of the layout as a ListView called mlistview.
        val mListView = findViewById<ListView>(R.id.mListView)

        // STEP02. Calls the default ArrayAdapter to apply to the List.
        // ArrayAdapter.createFromResource(this, R.array.number, android.R.layout.simple_list_item_1);

        // STEP02. Calls the default ArrayAdapter to apply to the List.
        // ArrayAdapter.createFromResource(this, R.array.number, android.R.layout.simple_list_item_1);
        val mAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, list)

        // STEP03. Apply the Adapter to the list view.

        // STEP03. Apply the Adapter to the list view.
        mListView.adapter = mAdapter
    }
}

Results of ListView with Array Adapter


[Android] How to use ArrayAdapter in ListView

🇰🇷 Korean

2020.07.25 - [개발 창고/Android] - [Android] ListView에 ArrayAdapter 적용하기

 

[Android] ListView에 ArrayAdapter 적용하기

안드로이드 어플을 개발하다 보면 리스트뷰를 쓰는 경우가 많습니다. 웹이든 모바일이든 주로 사용자가 원하는 기능은 게시판형이 가장 많은데 (게시판만 개인화 잘해놔도 활용이 어마어마합

royzero.tistory.com

반응형

'개발 창고 > Android' 카테고리의 다른 글

[Android] How to use SeekBar  (32) 2024.03.24
[Android] How to apply SimpleAdapter to ListView  (65) 2024.03.04
[Android] How to use multiple shapes  (36) 2024.02.19
[Android] 폰트(font) 적용하기  (7) 2024.02.13
[Android] How to make round box  (62) 2024.02.13