Android automatic judgment is the linkify use of phone, url, and email methods _android

Source: Internet
Author: User

When we are in a edittext input phone or URL or Email , let Android automatically judge, when we enter the phone, we click on the input will call the phone program, When we enter the URL click will open the browser program. and linkify solved the problem very well.

Steps:

1. Layout UI

Copy Code code as follows:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >

<textview
Android:id= "@+id/tv"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>

<edittext
Android:id= "@+id/et"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>

<textview
Android:id= "@+id/tv1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"/>

</LinearLayout>


2. Implement in Mainactivity
Copy Code code as follows:

public class Mainactivity extends activity {

Private TextView TV;
Private EditText et;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);

TV = (TextView) Findviewbyid (R.ID.TV1);
ET = (edittext) Findviewbyid (r.id.et);
Et. Setonkeylistener (New Onkeylistener () {
@Override
public boolean OnKey (View v, int keycode, keyevent event) {
Tv.settext (Et.gettext ());
Decide whether to enter a URL or an email or a phonenumber, and connect to the system automatically
linkifyaddlinks (TV, Linkify.web_urls | linkify.email_addresses | Linkify.phone_numbers |);
return false;
}
});
}
}


ok! Easy way: In TextView, the following statement!

<textview
Android:id= "@+id/tv1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"

android:autolink= "Web|phone|email"
/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.