欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android字段驗(yàn)證的實(shí)例代碼

 更新時(shí)間:2016年05月13日 14:36:46   作者:zhupengqq  
這篇文章主要介紹了Android字段驗(yàn)證的實(shí)例代碼的相關(guān)資料,代碼簡(jiǎn)單易懂,具有參考借鑒價(jià)值,需要的朋友可以參考下

先給大家展示效果圖:

package com.example.walkerlogin1; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
import com.throrinstudio.android.common.libs.validator.Form; 
import com.throrinstudio.android.common.libs.validator.Validate; 
import com.throrinstudio.android.common.libs.validator.validate.ConfirmValidate; 
import com.throrinstudio.android.common.libs.validator.validate.OrTwoRequiredValidate; 
import com.throrinstudio.android.common.libs.validator.validator.EmailValidator; 
import com.throrinstudio.android.common.libs.validator.validator.NotEmptyValidator; 
import com.throrinstudio.android.common.libs.validator.validator.PhoneValidator; 
import com.throrinstudio.android.common.libs.validator.validator.UrlValidator; 
public class MainActivity extends Activity { 
private EditText etAccount, etNick, etPassword, etMotto, etEmail, 
etCity, etfoot,etHeight,etWeight,etExceptSteps; 
private Button bt_ok; 
private Form form; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
initView(); 
setListener(); 
validateForm(); 
} 
//格式驗(yàn)證 
private void validateForm() { 
// 1. 先創(chuàng)建個(gè)表單Form類用來裝控件 
form = new Form(); 
// 非空驗(yàn)證 
// 2. 然后創(chuàng)建Validate類,將被驗(yàn)證控件傳入 
Validate notEmptyValidate = new Validate(etAccount); 
// 3. 將這個(gè)Validate類addValidator加入(如:非空類型NotEmptyVerifior)類型驗(yàn)證類 
NotEmptyValidator notEmpty = new NotEmptyValidator(this); 
notEmptyValidate.addValidator(notEmpty); 
// 二選一 
OrTwoRequiredValidate orTwoRequiredValidate = new OrTwoRequiredValidate( 
etNick, etPassword); 
//密碼驗(yàn)證 
Validate notPassword = new Validate(etPassword); 
NotEmptyValidator not2Empty = new NotEmptyValidator(this); 
notPassword.addValidator(not2Empty); 
//城市不能為空 
Validate etCity2 = new Validate(etCity); 
NotEmptyValidator etCity1 = new NotEmptyValidator(this); 
etCity2.addValidator(etCity1); 
//手機(jī)號(hào)不能為空 
Validate etMotto1 = new Validate(etMotto); 
PhoneValidator phonevalidator=new PhoneValidator(this); 
etMotto1.addValidator(phonevalidator); 
// 郵件驗(yàn)證 
Validate emailValidate = new Validate(etEmail); 
EmailValidator emailValidator = new EmailValidator(this); 
emailValidator.setDomainName("qq\\.com");// 設(shè)置郵件規(guī)則:只能是QQ郵箱 
emailValidate.addValidator(emailValidator); 
// 重復(fù)密碼確認(rèn) 
// ConfirmValidate confirmValidate = new ConfirmValidate(et_password1, 
// et_password2); 
// 網(wǎng)址 
/*Validate urlValidate = new Validate(et_url); 
UrlValidator urlValidator = new UrlValidator(this); 
urlValidate.addValidator(urlValidator);*/ 
// 4. Form表單addValidates這個(gè)Validate類即可 
form.addValidates(notPassword); 
form.addValidates(notEmptyValidate); 
form.addValidates(orTwoRequiredValidate); 
form.addValidates(emailValidate); 
form.addValidates(etCity2); 
form.addValidates(etMotto1); 
//form.addValidates(confirmValidate); 
// form.addValidates(urlValidate); 
} 
private void setListener() { 
bt_ok.setOnClickListener(new OnClickListener() { 
public void onClick(View v) { 
// 5. 最后調(diào)用form.validate()驗(yàn)證即可,返回true表示驗(yàn)證通過。 
boolean flag = form.validate(); 
if(flag){ 
Toast.makeText(MainActivity.this, "驗(yàn)證成功!", Toast.LENGTH_LONG).show(); 
}else{ 
Toast.makeText(MainActivity.this, "驗(yàn)證失敗", Toast.LENGTH_LONG).show(); 
} 
} 
}); 
} 
private void initView() { 
etAccount = (EditText) findViewById(R.id.etAccount); 
etNick = (EditText) findViewById(R.id.etNick); 
etPassword = (EditText) findViewById(R.id.etPassword); 
etMotto = (EditText) findViewById(R.id.etMotto); 
etEmail = (EditText) findViewById(R.id.etEmail); 
etCity = (EditText) findViewById(R.id.etCity); 
etfoot = (EditText) findViewById(R.id.etfoot); 
etHeight = (EditText) findViewById(R.id.etHeight); 
etWeight = (EditText) findViewById(R.id.etWeight); 
etExceptSteps = (EditText) findViewById(R.id.etExceptSteps); 
bt_ok = (Button) findViewById(R.id.btnClick); 
} 
} 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/welcome_bg" 
android:orientation="vertical" > 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/welcome_bg" 
android:orientation="vertical" 
android:padding="10dp" 
tools:context=".RegistActivity" > 
<com.makeramen.roundedimageview.RoundedImageView 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/roundImage_head" 
android:layout_width="80dp" 
android:layout_height="80dp" 
android:layout_gravity="center_horizontal" 
android:gravity="center_horizontal" 
android:onClick="changePhoto" 
android:src="@drawable/test_photo" 
app:riv_border_color="#333333" 
app:riv_border_width="3dip" 
app:riv_corner_radius="10dip" 
app:riv_mutate_background="true" 
app:riv_oval="true" /> 
<EditText 
android:id="@+id/etAccount " 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etaccount" 
android:ems="10" 
android:hint="@string/etAccountrHint" > 
</EditText> 
<EditText 
android:id="@+id/etNick" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etnick" 
android:ems="10" 
android:hint="@string/etNickHint" /> 
<EditText 
android:id="@+id/etPassword" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etpassword" 
android:ems="10" 
android:inputType="textPassword" 
android:hint="@string/etpassword" 
> 
</EditText> 
<EditText 
android:id="@+id/etMotto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etmotto" 
android:ems="10" 
android:hint="@string/etMotto" > 
</EditText> 
<EditText 
android:id="@+id/etEmail" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etemail" 
android:ems="10" 
android:hint="@string/etMail" 
android:inputType="textEmailAddress" > 
</EditText> 
<EditText 
android:id="@+id/etCity" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etcity" 
android:ems="10" 
android:hint="@string/etCity" > 
</EditText> 
<View 
android:layout_width="match_parent" 
android:layout_height="2dp" 
android:background="@android:color/darker_gray" /> 
<EditText 
android:id="@+id/etfoot" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etfoot" 
android:ems="10" 
android:hint="@string/etStep" 
android:inputType="number" > 
</EditText> 
<EditText 
android:id="@+id/etHeight" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etheight" 
android:ems="10" 
android:hint="@string/etHeight" 
android:inputType="number" > 
</EditText> 
<EditText 
android:id="@+id/etWeight" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etweight" 
android:ems="10" 
android:hint="@string/etWeight" 
android:inputType="number" > 
</EditText> 
<EditText 
android:id="@+id/etExceptSteps" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@android:drawable/edit_text" 
android:drawableLeft="@drawable/etexceptsteps" 
android:ems="10" 
android:hint="@string/etExceptSteps" 
android:inputType="number" /> 
<TextView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:text="@string/etRegistFinish" > 
</TextView> 
<!-- <cn.edu.bztc.walkersimulate.util.RevealLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 
</cn.edu.bztc.walkersimulate.util.RevealLayout> --> 
<Button 
android:id="@+id/btnClick" 
android:layout_width="300dp" 
android:layout_height="55dp" 
android:layout_marginTop="5dp" 
android:background="@drawable/btn_select" 
android:gravity="center" 
android:text="@string/etCity" > 
</Button> 
</LinearLayout> 
</ScrollView> 

另外還需導(dǎo)入一個(gè)類庫Android-Validator-master

以上內(nèi)容是小編給大家介紹的android字段驗(yàn)證的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家想了解更多資訊敬請(qǐng)關(guān)注腳本之家網(wǎng)站!

相關(guān)文章

  • Android實(shí)現(xiàn)Path平滑的涂鴉效果實(shí)例

    Android實(shí)現(xiàn)Path平滑的涂鴉效果實(shí)例

    這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)Path平滑涂鴉效果的相關(guān)資料,通過本文介紹的方法修改后會(huì)讓線條平滑很多,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • Retrofit + OkHttp緩存處理的示例代碼

    Retrofit + OkHttp緩存處理的示例代碼

    本篇文章主要介紹了Retrofit + OkHttp緩存處理的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • Android如何調(diào)整線程調(diào)用棧大小

    Android如何調(diào)整線程調(diào)用棧大小

    這篇文章主要介紹了Android如何調(diào)整線程調(diào)用棧大小,幫助大家更好的進(jìn)行Android開發(fā),完善自身程序,感興趣的朋友可以了解下
    2020-10-10
  • Android內(nèi)存泄漏終極解決篇(下)

    Android內(nèi)存泄漏終極解決篇(下)

    這篇文章主要為大家介紹了Android內(nèi)存泄漏的相關(guān)資料,哪些寫法容易造成內(nèi)存泄漏,該如何解決?感興趣的小伙伴們可以參考一下
    2016-01-01
  • 退出Android程序時(shí)清除所有activity的實(shí)現(xiàn)方法

    退出Android程序時(shí)清除所有activity的實(shí)現(xiàn)方法

    這篇文章主要介紹了退出Android程序時(shí)清除所有activity的實(shí)現(xiàn)方法,詳細(xì)分析了Android退出時(shí)清除activity的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-04-04
  • Android開發(fā)之OpenGL繪制2D圖形的方法分析

    Android開發(fā)之OpenGL繪制2D圖形的方法分析

    這篇文章主要介紹了Android開發(fā)之OpenGL繪制2D圖形的方法,結(jié)合實(shí)例形式分析了Android使用OpenGL ES的圖形繪制組件實(shí)現(xiàn)2D圖形繪制的原理、步驟及相關(guān)代碼注意事項(xiàng),需要的朋友可以參考下
    2017-09-09
  • 手把手教你用ViewPager自定義實(shí)現(xiàn)Banner輪播

    手把手教你用ViewPager自定義實(shí)現(xiàn)Banner輪播

    這篇文章主要手把手教你用ViewPager自定義實(shí)現(xiàn)Banner輪播,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android App調(diào)用MediaRecorder實(shí)現(xiàn)錄音功能的實(shí)例

    Android App調(diào)用MediaRecorder實(shí)現(xiàn)錄音功能的實(shí)例

    這篇文章主要介紹了Android App調(diào)用MediaRecorder實(shí)現(xiàn)錄音功能的實(shí)例,MediaRecorder非常強(qiáng)大,不僅能夠用來錄制音頻還可以錄制視頻,需要的朋友可以參考下
    2016-04-04
  • android使用include調(diào)用內(nèi)部組件的方法

    android使用include調(diào)用內(nèi)部組件的方法

    這篇文章主要介紹了android使用include調(diào)用內(nèi)部組件的方法,涉及Android組件調(diào)用的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Flutter上線項(xiàng)目實(shí)戰(zhàn)記錄之路由篇

    Flutter上線項(xiàng)目實(shí)戰(zhàn)記錄之路由篇

    這篇文章主要給大家介紹了關(guān)于Flutter上線項(xiàng)目實(shí)戰(zhàn)記錄之路由篇的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論