Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch a URL in browser from an OnClick event on a TextView?

I have read the answer "How do I launch a URL in the browser from my Application on Android" but I am still confused.

------> Basically I have a TextView that will be displaying different names of famous people, and what I want is, to perform a google search in the browser that searches for the text that is currently displayed in the TextView, when the user clicks on the TextView itself.

Thanks.

like image 876
Moderation Avatar asked Jan 18 '26 09:01

Moderation


2 Answers

in onClickListner event write this code:

String url = textView.getText().toString();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
like image 140
Awais Tariq Avatar answered Jan 21 '26 02:01

Awais Tariq


Well, what I understand is that you want to launch Google search for the text when you click on the TextView. Here is a code to directly launch Google search of the text provided:

String searchKey = "Text From your TextView";
Intent search = new Intent(Intent.ACTION_WEB_SEARCH);  
search.putExtra(SearchManager.QUERY, searchKey);  
startActivity(search);  
like image 45
Khawar Avatar answered Jan 21 '26 00:01

Khawar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!