Is R..layout.listview the same as R.id.listview

I am new to Android programming. I created a ListView and its android:id="@+id/listView1"

 ListView list= (ListView) findViewById(R.id.listView1); ListView list= (ListView) findViewById(R.layout.listView1); 

Will it reference the same ListView? Is there a difference between the two fragments?

+6
source share
3 answers

No. Both variants.

R.id.listView1: -

Represents the view identifier that is declared in the layout (your XML file) as android:id="@+id/listView1"

and

R.layout.listView1: -

Represents a layout file (xml file), which in res -> layout dir


You can do

 ListView list= (ListView) findViewById(R.id.listView1); 

because ListView has a View family.

But you cannot do

 ListView list= (ListView) findViewById(R.layout.listView1); 
+10
source

Both represent various means.

 android:id="@+id/listView1" 

represent a widget inside a layout (XML file) that has an attribute as follows: -

 android:id="@+id/listView1" 

where as R.layout.listView1 shows that you have an XML file in the layout folder named listView1 .

therefore both options.

0
source
 android:id="@+id/listView1" 

this may be the id of the list you created in the xml file.

 ListView list= (ListView) findViewById(R.id.listView1); 

and ou represent the list in your java file, calling the identifier.

 ListView list= (ListView) findViewById(R.layout.listView1); 

this is a way of representing the layout in your java file by calling the layout id

0
source

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


All Articles