0

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

Siavash
  • 7,583
  • 13
  • 49
  • 69

1 Answers1

1

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!

  • So the tag I put in my layout file doesnt actually create a list view? is it just a placeholder? thats the confusing part. – Siavash Apr 18 '13 at 02:12
  • 1
    It does create a ListView, it's just designed to hold a single item, like a string of text, or an image. By using an adapter and a custom row layout, you can put practically whatever you want in each row, specifically, more than just a single string or image, you can have multiples of each or any combination of elements. – flapjack.fiasco Apr 18 '13 at 02:17