[Android] How to use ArrayAdapter in ListView
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)
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
}
}
[Android] How to use ArrayAdapter in ListView
🇰🇷 Korean
2020.07.25 - [개발 창고/Android] - [Android] ListView에 ArrayAdapter 적용하기