Search code examples
androidhttp-redirecttextclickable

To make a particular part of my text clickable


I'm tring to make a particular part of my text clickable. Please see the below image for example: In this Image I would like to make "www.google.com" clickable

In this image "www.google.com" is placed inside an expandable listview. Can anyone please help me how I can make this text clickable so that it re-directs to its corresponding web page

ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();

public void setGroupData() {
    groupItem.add("About");
    groupItem.add("General Information");
    groupItem.add("Contact");
}

public void setChildGroupData() {
    /**
     * Add Data For TecthNology
     */
    ArrayList<String> child = new ArrayList<String>();
    child.add(ConstantVariables.profile_description_full);
    childItem.add(child);

    child = new ArrayList<String>();
    child.add("Industry: "
            + ConstantVariables.profile_selectMultipleIndustry);
    childItem.add(child);

    child = new ArrayList<String>();
    child.add(ConstantVariables.profile_cityName_full + ", "
            + ConstantVariables.profile_countryName_full + '\n'
            + ConstantVariables.profile_websiteAddress_full);
    childItem.add(child);
}

Here's my code for reference.


Solution

  • Try and include the following in the TextView definition in XML file:

    <TextView
        ...
        android:autoLink="web"/>
    

    The docs of android:autoLink say:

    Controls whether links such as urls and email addresses are automatically found and converted to clickable links

    So for automatically finding links, the above may help. Try and see.