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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With