Reputation: 141
I'm fairly new to developing for android; this is my first app. I let Android Studio generate a standard navigation drawer app. Ideally I want to be able to click on an item in the navigation drawer and then a webview loads the clicked website. I made a webview in the .xml
file with id main_webview
. What should I change to the onItemClick
method to change the url?
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
Upvotes: 2
Views: 1401
Reputation: 317
WebView webpage = (WebView) findViewById(R.id.main_webview);
String pageUrl = "http://any-url-you-want/";
...onItemClick(params...){
webpage.loadUrl(pageUrl);
}
Upvotes: 2