What is textViewResourceId?

I am trying to understand how to use the ArrayAdapter class, and from the docs: http://developer.android.com/reference/android/widget/ArrayAdapter.html , I see that the constructor expects an integer textViewResourceId.

What it is?

Edit: From a bit more research and answers here, it looks like it should be the TextView identifier that I defined in the XML file that contains the interface code. But I saw this example here:

ArrAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,myArrayList)

So, how can you use android.R.layout.simple_list_item_1 here? What does this really mean? I am only familiar with using R.id.idOfMyViewHere

+6
source share
4 answers

this is the textview identifier in which the adapter updates the information you provide. You can use textview provided by android:

 android.R.id.text1 

eg. Or you can provide your own textview with your user id

Edit

changes:

 ArrayAdapter(this,android.R.layout.simple_list_item_1,myArrayList) 

from

 ArrayAdapter(this,android.R.id.text1,myArrayList) 
+4
source

android.R.layout.simple_list_item_1 is the default layout if you want to use your layout and you can also use it as

new ArrayAdapter<String>(context, layout_id, textview_id, items);

+5
source

textViewResourceId is an identifier for a specific layout. To refer to this identifier, you use the R.layout format. *.

R.layout. * are the layouts you created in the res / layout folder. Therefore, if you have an xml layout file in the res / layout / folder folder called "my_list_item.xml" of any layout format you want, you can use it as your textViewResourceId (not necessarily TextView).

If you do not want to create your own layout, you can use the built-in layouts found in your android-sdk directory (in my case its C: \ Android \ android-sdk \ platform \ android-8 \ Data \ Res \ layout). You reference these inline layouts via android.R.layout. * (Notification I started with "android"). Therefore, if I want to use the built-in simple_list_item_1.xml file, I can reference this using the android.R.layout.simple_list_item_1 file.

R.layout. * <--- own layout
android.R.layout. * <--- built-in Android layouts

Some popular layouts:
android.R.simple_list_item_1
simple_list_item_2.xml
and etc.

+1
source

from documents:

A specific BaseAdapter that is supported by an array of arbitrary objects. By default, this class expects the provided resource identifier to reference a single TextView.

simple, by default it is binding to textView, and text view

TextView identifier in the layout resource to be populated

0
source

Source: https://habr.com/ru/post/912476/


All Articles