在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:AValidations开源软件地址:https://gitee.com/quanke/AValidations开源软件介绍:#AValidations android表单验证框架
AValidations使用
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; }}
public class LoginActivity extends Activity implements OnClickListener{private EditText usernameEditText;private EditText passwordEditText;private Button loginButton;private EditTextValidator editTextValidator;@Overrideprotected 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; } }
<?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> Copyright 2014 ken.cai (http://quanke.name) Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. |
请发表评论