Reputation: 275
What exactly does this block of code (below) do?
WebView browser = (WebView) findViewById(R.id.activity_main_webview)
I have used it in my WebView app I started, and it seems to be important, but I don't understand what it does.
Upvotes: 0
Views: 70
Reputation: 828
To say simple and short:
In android you define UI (for example layout of your activities) in some xml file. Each component in layout of activities could have an Id. Android automatically create some java files to relate defined id to real components (IDs will save in a file/class which android named it R.java) So when you want to access real component defined in xml file in the java code (for example in activity source code) you could use method findById and send id of requested component to it. This method returns real component (java object) related to given id.
Upvotes: 1
Reputation: 134
It just references to your webview view on the basis of ID you have given to view.
Upvotes: 3