亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android 自動(dòng)判斷是電話,網(wǎng)址,EMAIL方法之Linkify的使用

 更新時(shí)間:2013年04月21日 10:27:25   作者:  
本篇文章小編為大家介紹,在Android中 自動(dòng)判斷是電話,網(wǎng)址,EMAIL方法之Linkify的使用。需要的朋友參考下

當(dāng)我們?cè)谝粋€(gè)EditText輸入電話或者網(wǎng)址還是Email的時(shí)候,讓Android自動(dòng)判斷,當(dāng)我們輸入的是電話,我們點(diǎn)擊輸入內(nèi)容將調(diào)用打電話程序,當(dāng)我們輸入是網(wǎng)址點(diǎn)擊將打開瀏覽器程序.而Linkify很好的解決了這個(gè)問題

步驟:

1、布局UI

復(fù)制代碼 代碼如下:

<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、在MainActivity中實(shí)現(xiàn)
復(fù)制代碼 代碼如下:

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());
    // 判斷輸入的是URL還是EMAIL還是PHONENUMBER,并自動(dòng)與系統(tǒng)連接
    Linkify.addLinks(tv, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS |);
    return false;
   }
  });
 }
}


OK!簡(jiǎn)便方法:在TextView中如下申明!

<TextView
 android:id="@+id/tv1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"

 android:autoLink="web|phone|email"
/>

相關(guān)文章

最新評(píng)論