I have a list view with items [google, yahoo, bing ...]
. By clicking on each item a webview must be loaded with the corresponding URL. My problem is that I have created a list view with items in it but I need only one class for loading all the URLs. So when I click on google the webview must load the google website and if I press yahoo it must load the yahoo website in the same webview.
I want to pass the URL of the clicked item to the next page (webview).
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateListView();
clickEvent();
}
private void populateListView() {
String[] str={"Google","yahoo", "bing"};
ArrayAdapter<String>adapter=new ArrayAdapter<String>(this, R.layout.textview,str);
ListView list=(ListView)findViewById(R.id.listviewone);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
}
private void clickEvent() {
final ListView list=(ListView)findViewById(R.id.listviewone);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
view.setSelected(true);
switch( position )
{
case 0: Intent newActivity0 = new Intent(MainActivity.this, Mywebpage.class);
startActivity(newActivity0);
break;
}
}
});
}
Mywebpage.java
public class Mywebpage extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewpage);
WebView wbView = (WebView) findViewById(R.id.WebView);
wbView.getSettings().setJavaScriptEnabled(true);
wbView.loadUrl("http://www.google.com");
}
}