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

EditText實(shí)現(xiàn)輸入限制和校驗(yàn)功能實(shí)例代碼

 更新時(shí)間:2017年08月06日 09:02:57   作者:玄鐵  
本文通過(guò)實(shí)例代碼給大家介紹EditText實(shí)現(xiàn)輸入限制和校驗(yàn)功能,感興趣的朋友參考下吧

一、方法

1)輸入限制

1、通過(guò)android:digits限制只能輸入小寫(xiě)abc

android:digits="abc"

2、通過(guò)android:inputType限制只能輸入數(shù)字

android:inputType="number"

在android:inputType中可以設(shè)置各種限制,比如郵箱地址等等

2)校驗(yàn)

直接通過(guò)代碼實(shí)現(xiàn)

String s=et_verify_empty.getText().toString();
 if(s==null||s.length()==0){
  et_verify_empty.setError("不能為空");
 }

二、代碼實(shí)例

效果圖

代碼

fry.ActivityDemo2

package fry;
import com.example.editTextDemo1.R;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class ActivityDemo2 extends Activity implements OnClickListener{
  private EditText et_verify_empty;
  private Button btn_verify;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity02);
    setTitle("EditText實(shí)現(xiàn)輸入限制和校驗(yàn)");
    et_verify_empty=(EditText) findViewById(R.id.et_verify_empty);
    btn_verify=(Button) findViewById(R.id.btn_verify);
    btn_verify.setOnClickListener(this);
  }
  @Override
  public void onClick(View arg0) {
    // TODO Auto-generated method stub
    String s=et_verify_empty.getText().toString();
    //if(s==null||s.length()==0){
    if(TextUtils.isEmpty(s)){
      et_verify_empty.setError("不能為空");
    }
  }
}

/editTextDemo1/res/layout/activity02.xml

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="通過(guò)android:digits限制只能輸入小寫(xiě)abc"
    />
  <EditText 
    android:id="@+id/et_limit_abc"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="abc"
    />
   <TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="通過(guò)android:inputType限制只能輸入數(shù)字"
    />
   <!-- 在android:inputType中可以設(shè)置各種限制,比如郵箱地址等等 -->
  <EditText 
    android:id="@+id/et_limit_number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    />
  <TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="通過(guò)代碼校驗(yàn)EditText是否為空"
    />
   <!-- 在android:inputType中可以設(shè)置各種限制,比如郵箱地址等等 -->
  <EditText 
    android:id="@+id/et_verify_empty"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType=""
    />
  <Button 
    android:id="@+id/btn_verify"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="開(kāi)始校驗(yàn)"
    />
</LinearLayout>

總結(jié)

以上所述是小編給大家介紹的EditText實(shí)現(xiàn)輸入限制和校驗(yàn)功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

  • Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法

    Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法,涉及Android權(quán)限控制、布局及攝像頭功能調(diào)用等相關(guān)操作技巧,需要的朋友可以參考下
    2017-09-09
  • Android編程中TextView寬度過(guò)大導(dǎo)致Drawable無(wú)法居中問(wèn)題解決方法

    Android編程中TextView寬度過(guò)大導(dǎo)致Drawable無(wú)法居中問(wèn)題解決方法

    這篇文章主要介紹了Android編程中TextView寬度過(guò)大導(dǎo)致Drawable無(wú)法居中問(wèn)題解決方法,以實(shí)例形式較為詳細(xì)的分析了TextView設(shè)置及xml布局與調(diào)用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android UI效果之繪圖篇(一)

    Android UI效果之繪圖篇(一)

    這篇文章主要介紹了Android UI效果之繪圖篇,針對(duì)Android開(kāi)發(fā)中的UI效果設(shè)計(jì)模塊進(jìn)行講解,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android實(shí)現(xiàn)多線程下載文件的方法

    Android實(shí)現(xiàn)多線程下載文件的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)多線程下載文件的方法,以實(shí)例形式較為詳細(xì)的分析了Android多線程文件傳輸及合并等操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android Studio 引入 aidl 文件的方法匯總

    Android Studio 引入 aidl 文件的方法匯總

    本文給大家分享的是在Android Studio中引入AIDL文件常用的兩種方法,小伙伴們根據(jù)自己的情況自由選擇,希望對(duì)大家能夠有所幫助
    2017-11-11
  • Android實(shí)現(xiàn)自定義飄雪效果

    Android實(shí)現(xiàn)自定義飄雪效果

    隨著冬季的腳步越來(lái)越遠(yuǎn),南方的我今年就看了一場(chǎng)雪,下一場(chǎng)雪遙遙無(wú)期,那我們來(lái)實(shí)現(xiàn)一個(gè)自定義的 View,它能模擬雪花飄落的景象,所以本文給大家介紹了基于Android實(shí)現(xiàn)自定義飄雪效果,感興趣的朋友可以參考下
    2024-01-01
  • Android登錄界面的實(shí)現(xiàn)代碼分享

    Android登錄界面的實(shí)現(xiàn)代碼分享

    好久沒(méi)有搞android項(xiàng)目了,手都有點(diǎn)松了,今天因?yàn)轫?xiàng)目的需要,繼續(xù)弄android知識(shí),在項(xiàng)目中登錄界面是項(xiàng)目中比較常見(jiàn)的最基本的功能,對(duì)android登錄界面的實(shí)現(xiàn)感興趣的朋友一起學(xué)習(xí)吧
    2016-11-11
  • 詳解Android Studio安裝ButterKnife插件(手動(dòng)安裝)

    詳解Android Studio安裝ButterKnife插件(手動(dòng)安裝)

    這篇文章主要介紹了詳解AndroidStudio安裝ButterKnife插件(手動(dòng)安裝),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Android開(kāi)發(fā)筆記之:Dialog的使用詳解

    Android開(kāi)發(fā)筆記之:Dialog的使用詳解

    本篇文章是對(duì)Android中Dialog的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    這篇文章主要為大家介紹了android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11

最新評(píng)論

闵行区| 广西| 巧家县| 安龙县| 冀州市| 金溪县| 龙州县| 日土县| 鹿泉市| 海城市| 虎林市| 钟山县| 荥阳市| 资兴市| 武陟县| 都昌县| 扎鲁特旗| 开原市| 宁夏| 湘潭县| 友谊县| 新和县| 吉安市| 大港区| 远安县| 浑源县| 保亭| 伽师县| 江山市| 广德县| 炉霍县| 明光市| 甘肃省| 南靖县| 定西市| 株洲市| 勐海县| 松阳县| 孟津县| 昌都县| 湟源县|