Reputation: 535
ListView listView = (ListView) findViewById(R.id.listview);
It would be understandable for me if it was something like
ListView listView = new ListView()
But I don't understand what the RHS of ListView listView = (ListView) findViewById(R.id.listview) means; I know that LHS creates a reference variable named listView which will contain the reference to an object of ListView.
To the best of my understanding, is it retrieving a view by findViewById() and parsing to a ListView object (how can an object of one type be even parsed into an object of another type) , and then assigning a reference to that ListView object in listView reference variable? Thank you in advance.
Upvotes: 0
Views: 176
Reputation: 574
R.id.listview
here in one of your xml layouts you name a list as "listview"
android assigns id to every name you allot. id are stored in R java file it would be like
public static final int listview=0x7f050002;
even you could directly use this int value in place of R.id.listview
findViewById(R.id.listview);
this will tell your activity to find a view (whose id is stored as R.id.listview)
(listview)
you are casting your view as a LISTVIEW object
and assigning it to the
listView
object of class ListView
Upvotes: 1