最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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)論

涿鹿县| 保康县| 虎林市| 翼城县| 宁国市| 嵩明县| 福泉市| 鄂尔多斯市| 绥滨县| 郴州市| 沐川县| 广东省| 涞源县| 射洪县| 阿鲁科尔沁旗| 梧州市| 鄄城县| 广昌县| 肥城市| 石屏县| 若尔盖县| 德化县| 孟州市| 浠水县| 遵义市| 永春县| 巢湖市| 抚顺市| 霸州市| 无极县| 大厂| 什邡市| 凤山县| 灌阳县| 长子县| 泸西县| 克东县| 榆树市| 探索| 饶河县| 公主岭市|