1

What is the main difference between these If my layout file is R.layout.custom_layout

There are lot of tutorials are just placing on behalf of resourceId is R.layout.custom_layout .

And on behalf of textViewRourceId is just placing an id of TextView that was declared in R.layout.custom_layout

ArrayAdapter(Context context,int resourceId,int textViewResourceId,List list)

and

ArrayAdapter(Context context,int resourceId,List list)

I really in doubt where should i use and why?

1)In my point of view In custom Adapter both work same

2)I couldn't understand the first constructor parameter int textViewResourceId.How/Why does the parameter use?

3)May is used an other textViewResourceId that was not declare in the R.layout.custom_list

Thanks

2 Answers2

0

For ArrayAdapter(Context context,int resourceId,List list)

The common example is any data that you want to toString(), you use android.R.layout.simple_list_item_1.

For the other constructor, you have to provide a layout that contains a TextView and give both the parent layout and the id of that TextView as the parameter. That TextView cannot be from another layout.

Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Can you please explain it why the TextView should be from the resource layout and how this TextView implements in ArrayAdapter?Any example.. – waqas akram Jun 02 '16 at 15:46
  • I'm not sure the underlying specifics of ArrayAdapter, but the textview should be inside the resource because otherwise how would you know where or how to show the text? It uses findViewById, most likely... You would use a custom layout only when you don't want your data to be whatever the default is (left-aligned, medium font, the current theme text color, etc) – OneCricketeer Jun 02 '16 at 16:41
0

Normally, if you want to have custom adapter, better to use BaseAdapter instead. For 2 usages: ArrayAdapter(Context context,int resourceId,List list) - Layout should have only 1 view that's TextView

ArrayAdapter(Context context,int resourceId,int textViewResourceId,List list) - Custom layout can be complex and contain at least 1 TextView which have ID as param textViewResourceId in the constructor.

https://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, int, T[])

Minh LEE
  • 26
  • 1
  • There's nothing wrong with extending ArrayAdapter instead of BaseAdapter, plus it gives additional implementations of common arraylist methods – OneCricketeer Jun 02 '16 at 14:01
  • Nice!but Can you please explain it why the TextView should be from the resource layout and how this TextView implements in ArrayAdapter?Any example. – waqas akram Jun 02 '16 at 15:47
  • @cricket_007 I agreed, but if in future, u want to have more demand, easier to u. Just my experience only. – Minh LEE Jun 03 '16 at 05:42