如何从TextView上的OnClick事件启动浏览器中的URL?

时间:2011-12-02 05:40:19

标签: android url textview launch

我已经阅读了答案“如何在Android上的应用程序中在浏览器中启动URL”,但我仍感到困惑。

------> 基本上我有一个TextView,它将显示不同名人的名字,我想要的是,当用户点击TextView本身时,在浏览器中执行谷歌搜索,搜索当前显示在TextView中的文本

感谢。

2 个答案:

答案 0 :(得分:10)

在onClickListener事件中

写下这段代码:

String url = textView.getText().toString();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

答案 1 :(得分:1)

嗯,我的理解是,当您单击TextView时,您想要启动Google搜索文本。以下是直接启动Google搜索所提供文字的代码:

String searchKey = "Text From your TextView";
Intent search = new Intent(Intent.ACTION_WEB_SEARCH);  
search.putExtra(SearchManager.QUERY, searchKey);  
startActivity(search);