Tuesday, July 9, 2013

[android help] Is R.layout.listview is same as R.id.listview


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


android - Is R.layout.listview is same as R.id.listview - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















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?





























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);






















Both are representing different means.



android:id="@+id/listView1"


represent an widget inside an layout (XML file) that have Attribute as follows :-



android:id="@+id/listView1"


where as R.layout.listView1 shows you have a XML file in your layout folder named as listView1.


so both are different.


























android:id="@+id/listView1"


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



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


and ou are representing the listview in your java file by calling the id.



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


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




















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...