欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

EditText如何實現(xiàn)輸入限制和校驗功能-創(chuàng)新互聯(lián)

這篇文章主要介紹了EditText如何實現(xiàn)輸入限制和校驗功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比田東網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式田東網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋田東地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

一、方法

1)輸入限制

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

android:digits="abc"

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

android:inputType="number"

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

2)校驗

直接通過代碼實現(xiàn)

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

二、代碼實例

效果圖

EditText如何實現(xiàn)輸入限制和校驗功能

代碼

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實現(xià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中可以設置各種限制,比如郵箱地址等等 -->
  <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="通過代碼校驗EditText是否為空"
    />
   <!-- 在android:inputType中可以設置各種限制,比如郵箱地址等等 -->
  <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="開始校驗"
    />
</LinearLayout>

感謝你能夠認真閱讀完這篇文章,希望小編分享的“EditText如何實現(xiàn)輸入限制和校驗功能”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關知識等著你來學習!

網(wǎng)頁名稱:EditText如何實現(xiàn)輸入限制和校驗功能-創(chuàng)新互聯(lián)
鏈接地址:http://www.chinadenli.net/article14/psdde.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)域名注冊自適應網(wǎng)站App設計關鍵詞優(yōu)化響應式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)