Amerrnath Amerrnath - 3 years ago 37
Android Question

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?

Answer Source

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); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download