Android Linkify Example

The Linkify class is used to create the links from the TextView or the Spannable. It converts the text and regular expression to the clickable links on the basis of the pattern match of text value and the regex. The Linkify class creates the links for web URL, email address, phone number, and map address by using pattern.

Android clickable links can be created by two different ways:

1. Using layout (.xml) file: it uses autoLink attribute with the specified type.

2. Using Java class: it uses the addlLinks() method with specified types of Linkify class.

Android Linkify Example

In this example, we will create links for the web URL, email address and phone number. Create an activity_main.xml file in layout directory and add the following code.

activity_main.xml


Create a custom layout myList.xml file and add the following code. In this layout, we use autoLink attribute with the web, email, and phone property.

myList.xml


Create an adapter class MyListActivity.java and extends ArrayAdapter<> with the following code.

MyListActivity.java


Finally, in the MainActivity.java class, set the adapter instance to ListView.

MianActivity.java

Output:

Android Linkify Example Android Linkify Example Android Linkify Example
Next TopicIntro Slider




Contact US

Email:[email protected]

Android Linkify
10/30