Вопрос

I understand that simple_list_item_1 is a pre written xml layout file that we use when we are creating a listview.
We pass it in as one of the parameters to the constructor of ArrayAdapter<>. But why do we need a middleman?
the android manual on this constructor says that the parameter needs to be "The resource ID for a layout file containing a layout to use when instantiating views." But all the I want to understand why in all the examples I've seen, they use simple_list_item_1, instead of just passing in their own layout file which contains the ListView they want to populate.

Thanks

Это было полезно?

Решение

Most likely because it is easy to use canned code that is readily available. If there's no need to write your own layout, why bother? But if there is some need for customization, then make your own layout and pass that through instead. Here's a link to a tutorial for an SMS app that uses a custom layout for rows in a ListView:

http://adilsoomro.blogspot.com/2012/12/android-listview-with-speech-bubble.html

Hope that helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top