Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
开发者_开发问答 Improve this questionI can't find a way to make this code work, please help.
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(Main.this, "ID '" + o.get("id")+"' url '"+ o.get("url") + "' was clicked.", Toast.LENGTH_LONG).show();
Intent browserIntent = new Intent("android.intent.action.VIEW",Uri.parse(o.get("url")));
startActivity(browserIntent);
}
Try the following code:
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/"));
startActivity(myIntent);
open URL in WebView
public void openNewActivity(View view) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
mWebView.loadUrl("http://google.com");
}
open URL in Default Browser
public void openNewActivity(View view) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://google.com"));
startActivity(myWebLink);
}
Your code is wrong, it should be:
Intent browserIntent = new Intent(android.intent.action.VIEW,Uri.parse(o.get("url")));
startActivity(browserIntent);
And yes don't forget to add INTERNET Permission in the AndroidManifest.xml file.
精彩评论