<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          AValidationsAndroid 表單驗證

          聯(lián)合創(chuàng)作 · 2023-09-24 10:38

          AValidations 是 一個免費(fèi)的、開源的、簡易的、遵循Apache Licence 2.0開源協(xié)議發(fā)布,超級容易擴(kuò)展的android表單驗證的小框架

          使用方法:

          1.下載zip或者克隆AValidations項目
          2.導(dǎo)入Eclipse,右鍵工程->preference->Android->library->Add,選擇AValidations工程加入后 apply應(yīng)用
          3.繼承ValidationExecutor寫出自己的校驗器:

          public class UserNameValidation extends ValidationExecutor {
              public boolean doValidate(Context context, String text) {
          
                  String regex = "^[a-zA-Z](?=.*?[a-zA-Z])(?=.*?[0-9])[a-zA-Z0-9_]{7,11}$";
                  boolean result = Pattern.compile(regex).matcher(text).find();
                  if (!result) {
                      Toast.makeText(context, context.getString(R.string.e_username_hint), Toast.LENGTH_SHORT).show();
                      return false;
                  }
                  return true;
              }
          }

          4.使用EditTextValidator進(jìn)行校驗:

          public class LoginActivity extends Activity implements OnClickListener{
              private EditText usernameEditText;
              private EditText passwordEditText;
              private Button loginButton;
              private EditTextValidator editTextValidator;
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_login);
          
                  usernameEditText = (EditText) findViewById(R.id.login_username_edittext);
                  passwordEditText = (EditText) findViewById(R.id.login_password_edittext);
                  loginButton = (Button) findViewById(R.id.login_button);
          
                  loginButton.setOnClickListener(this);
          
                  editTextValidator = new EditTextValidator(this)
                      .setButton(loginButton)
                      .add(new ValidationModel(usernameEditText,new UserNameValidation()))
                      .add(new ValidationModel(passwordEditText,new PasswordValidation()))
                      .execute();
          
              }
          
              @Override
                  public void onClick(View v) {
                      switch (v.getId()) {
                      case R.id.login_button:
          
                          if (editTextValidator.validate()) {
                              Toast.makeText(this, "通過校驗", Toast.LENGTH_SHORT).show();
                          }
                          break;
                      }
                  }

          5.如果需要實現(xiàn)沒有填寫表單時表單提交按鈕不可點(diǎn)擊效果 需要設(shè)置setButton(view)和寫B(tài)utton背景的selector,如:

          <?xml version="1.0" encoding="utf-8"?>
          <selector xmlns:android="http://schemas.android.com/apk/res/android">
          
          <item android:drawable="@drawable/red_btn_normal" android:state_focused="true" android:state_pressed="false"/>
          <item android:drawable="@drawable/red_btn_selected" android:state_focused="true" android:state_pressed="true"/>
          <item android:drawable="@drawable/red_btn_selected" android:state_focused="false" android:state_pressed="true"/>
          <item android:drawable="@drawable/red_btn_disable" android:state_enabled="false"/>
          
          <item android:drawable="@drawable/red_btn_normal"/>
          
          </selector>
          瀏覽 21
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  暴操网站| 黄片视频在线观看 | 99成人看的视频 | 日韩美一级片另类 | 嘛豆三级片电影 |