What is the second argument in ArrayAdapter() constructor?
What is the second argument in ArrayAdapter() constructor?
https://developer.android.com/guide/topics/ui/declaring-layout#FillingTheLayout
In these docs, we have this snippet:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, myStringArray);
It is then said that the second argument of the constructor is "The layout that contains a TextView for each string in the array." What does this mean? What is meant by a "layout"? How can such a Layout exist when my array could be of any size? What is this layout used for?
TextView
1 Answer
1
What is meant by a "layout"?
It is referring to a layout resource. Layout resources are covered in the page that you linked to.
What is this layout used for?
It will be used for rows in your ListView, or cells in your GridView, or other things depending on what AdapterView you use with your ArrayAdapter.
ListView
GridView
AdapterView
ArrayAdapter
How can such a Layout exist when my array could be of any size?
The layout resource will be used to provide the UI for a single item out of the array. As needed, your ArrayAdapter will create ListView rows using the layout resource. Think of it as a template for what an individual row in your list looks like.
ArrayAdapter
ListView
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.