Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am new to android programming. I have 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 refer the same ListView? Are there any difference between these two snippets?

like image 268
Amerrnath Avatar asked Jul 08 '13 06:07

Amerrnath


1 Answers

No Both are different.

R.id.listView1 :-

Represents the id of View which is declared in layout (your XML file) as android:id="@+id/listView1"

and

R.layout.listView1 :-

Represents the layout file (xml file) which into res -> layout dir


You can do

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

because ListView is of View family.

But you can't do

ListView list= (ListView) findViewById(R.layout.listView1); 
like image 160
Pankaj Kumar Avatar answered Sep 19 '22 10:09

Pankaj Kumar