Reputation: 119
I'm trying to figure out how to get from a List View to a Web View.
I have a list of different items, and depending on which item is selected I want to load a different URL for the Web View.
I cannot figure out how to do it in the same class because I cannot extend Activity and ListActivity.
I have tried making a switch statement depending on which list item was selected, and then assigning the URL and loading it in a different class, but that seems a little too complicated.
Is there an easier way to do this??
Upvotes: 0
Views: 1342
Reputation: 1271
I think you did the right thing:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
change(position);
}
void change(int position){
Uri uri;
switch(position){
case 1:
uri=Uri.parse(yourTextContaingUrl1);
case 2:
uri=Uri.parse(yourTextContaingUrl2);
case 3:
uri=Uri.parse(yourTextContaingUrl3);
}
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Upvotes: 2
Reputation: 200657
I cannot figure out how to do it in the same class because I cannot extend Activity and ListActivity.
ListActivity extends Activity...
Upvotes: 1
Reputation: 16363
This will call WebView for given URL
Uri uri=Uri.parse(yourTextContaingUrl);
intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
return true;
Upvotes: 1