I'm recieving an url like "http://www.msn.com" from the server. I want to display a textview which says click here, on clicking it the url should open in a browser. how to take the url and make a textview link for it and on click open a website.
Asked
Active
Viewed 138 times
-1
-
the url that is coming from the server is in 2 formats , one is like this "Test Survey Question" and other is like http://www.msn.com. so could you also suggest me a generalised format to handle both the kinds of response. – UserName_Untold Mar 23 '16 at 06:01
-
i already have a way to handle the first kind of response, please could you tell me how to handle the second one. – UserName_Untold Mar 23 '16 at 06:03
-
if you need partially clickable textview .http://stackoverflow.com/questions/34140815/partially-clickable-textview-and-different-text-colors-for-the-text-android/34147019#34147019 – Dhinakaran Thennarasu Mar 23 '16 at 06:08
-
http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable – Dhinakaran Thennarasu Mar 23 '16 at 06:09
-
i want to know how to handle the url "www.msn.com" and how it should be set to a textview. – UserName_Untold Mar 23 '16 at 06:11
-
1you dont need to set the link to textview. just do onclickListner for textview(clickhere ) in that write code to open the link you got from server – Dhinakaran Thennarasu Mar 23 '16 at 06:13
-
i dont know in which format im getting the url from the server it may either be embedded in an anchor tag like this "Test Survey Question" or just a simple url like "http://www.msn.com" so there has to be a method to check the format and then convert it into a link and open it in a browser. how to write a generalised method to check the format? – UserName_Untold Mar 23 '16 at 06:19
2 Answers
0
Since your getting the data from server in JSON format I hope definitely you will use the data in any adapter and data gets sent to each and every view. So implement an on-click listener inside the display adapter and whenever u click that text view pass that URL got from the server into that view. Then it will open the required URL in a browser.

Naveen
- 66
- 10
0
Either You can use android:autoLink="web"
for that TextView
and setting text as URL
Or You set onClick
for that link and add following Intent in onClick
String url = "http://www.google.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent );

Mr.India
- 674
- 2
- 9
- 19