How to create Textview Links - XML, Android -


I am trying to create a page with useful links within my app. I have the names of the websites displayed in the form of text pictures on the page, I want them to be clickable and bring the user to the desired website.

XML code:

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; RelativeLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" Android: Layout_width = "Match_parent" Android: Layout_height = "Match_parent" android: background = "@ color / white" & gt; & Lt; Android: layout_alignParentTop = "true" Android: layout_centerHorizontal = "true" Android: layout_marginTop = "28dp" Android: text = "id =" txtDepression101 "android: layout_width =" wrap_content "Android: layout_height =" wrap_content " = "Useful Links" Android: Text Appointment = "Android: ATR / Text Administration Large" /> & Lt ;! - https://www.facebook.com/UCCHealthMatters - & gt; & Lt; TextView android: id = "@ + id / TextView01" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignLeft = "@ + id / textView1" Android: layout_below = "@ + id / textView1" Android: Text = "UCC Health Affairs Twitter" /> & Lt ;! - https://twitter.com/UCCHealthMatter -> & Lt; TextView android: id = "@ + id / TextView04" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignLeft = "@ + id / TextView03" Android: layout_below = "@ + id / TextView03" Android: Text = "hse" /> & Lt ;! - http://www.hse.ie/eng/ - & gt; & Lt; TextView android: id = "@ + id / TextView02" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: layout_below = "@ + id / TextView01" Android: layout_centerHorizontal = "true" android: text = "Aware "/> & Lt ;! - https://aware.ie/ - & gt; & Lt; TextView android: id = "@ + id / textView1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_below = "@ + id / txtDepression101" Android: layout_centerHorizontal = "true" Android: layout_marginTop = "28 DP "Android: Text =" UCC Health Case Facebook "/> & Lt; TextView android: id = "@ + id / TextView03" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_below = "@ + id / TextView02" Android: layout_centerHorizontal = "true" android: text = "GROW "/> & Lt ;! - https://grow.ie/ - & gt; & Lt; TextView android: id = "@ + id / TextView05" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignRight = "@ + id / TextView01" Android: layout_below = "@ + id / TextView04" Android: Text = "mental health island" /> & Lt ;! - http://www.mentalhealthireland.ie/ - & gt; & Lt; TextView android: id = "@ + id / TextView06" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: layout_below = "@ + id / TextView05" Android: layout_centerHorizontal = "true" android: text = "Smrtin "/> & Lt ;! - http://www.samaritans.org/ - & gt; & Lt; TextView android: id = "@ + id / TextView07" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignLeft = "@ + id / TextView04" Android: layout_below = "@ + id / TextView06" Android: Text = "shine" /> & Lt ;! - http://www.shineonline.ie/ - & gt; & Lt; TextView android: id = "@ + id / TextView08" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_centerHorizontal = "true" Android: layout_centerVertical = "true" android: text = "Pieta House" / Gt; & Lt ;! - http://www.pieta.ie/ - & gt; & Lt; TextView android: id = "@ + id / TextView09" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: layout_below = "@ + id / TextView08" Android: layout_centerHorizontal = "true" android: text = "Reach Out Ireland "/> & Lt ;! - http://ie.reachout.com/ - & gt; & Lt; / RelativeLayout & gt;  

You can get like this:

 < Code> TextView textView = (TextView) findViewById (R.id.textView); TextView.setClickable (true); TextView.setText (Html.fromHtml ("& lt; a href = 'http: //www.google.com'> Google & lt; / a & gt;")); TextView.setMovementMethod (LinkMovementMethod.getInstance ());  

For others, do this like TextViews


Comments