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

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

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

一、方法

1)輸入限制

1、通過android:digits限制只能輸入小寫abc

android:digits="abc"

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

android:inputType="number"

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

2)校驗(yàn)

直接通過代碼實(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="通過android:digits限制只能輸入小寫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="通過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="通過代碼校驗(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="開始校驗(yàn)"
    />
</LinearLayout>

總結(jié)

以上所述是小編給大家介紹的EditText實(shí)現(xiàn)輸入限制和校驗(yàn)功能,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時(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寬度過大導(dǎo)致Drawable無法居中問題解決方法

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

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

    Android UI效果之繪圖篇(一)

    這篇文章主要介紹了Android UI效果之繪圖篇,針對Android開發(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ù)自己的情況自由選擇,希望對大家能夠有所幫助
    2017-11-11
  • Android實(shí)現(xiàn)自定義飄雪效果

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

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

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

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

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

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

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

    本篇文章是對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

最新評論

九龙县| 墨玉县| 尼勒克县| 阜南县| 灵山县| 那坡县| 汉寿县| 南昌县| 大新县| 泰州市| 科技| 郴州市| 黑龙江省| 金华市| 安多县| 宾阳县| 库伦旗| 简阳市| 鄂伦春自治旗| 密山市| 北流市| 家居| 崇左市| 阿瓦提县| 江门市| 岳阳县| 贺州市| 澄迈县| 永州市| 黔南| 商南县| 太仆寺旗| 天柱县| 噶尔县| 桃园市| 吉安市| 沁阳市| 延吉市| 车险| 玉溪市| 正安县|