Search code examples
javaandroidandroid-recyclerviewplaintext

How to Handle link and number from plain text


I download user data, where I have a number, email, website and plain text in the description. My first question is how to find these links and number in text, recognize and use them? fe. when user click on the number, application should open new app to make phone call.

Example description text:

Lorem ipsum dolor sit amet, +44 798-09-09 consectetur adipiscing elit, sed do eiusmod tempor incididunt ut www.google.com et dolore magna aliqua. Ut enim ad minim veniam, quis address@gmail.com ullamco


Solution

  • Use autoLink attribute for TextView. It handles automatically all links and its clicks.

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"
        android:autoLink="phone" />
    

    You can also use autoLink="web" or autoLink="all".

    You can see all possible values for autoLink from its documentation.