本文整理汇总了Java中com.rengwuxian.materialedittext.MaterialEditText.addValidator方法的典型用法代码示例。如果您正苦于以下问题:Java MaterialEditText.addValidator方法的具体用法?Java MaterialEditText.addValidator怎么用?Java MaterialEditText.addValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rengwuxian.materialedittext.MaterialEditText
的用法示例。
在下文中一共展示了MaterialEditText.addValidator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initValidationEt
import com.rengwuxian.materialedittext.MaterialEditText; //导入方法依赖的package包/类
private void initValidationEt() {
final MaterialEditText validationEt = (MaterialEditText) findViewById(R.id.validationEt);
validationEt.addValidator(new RegexpValidator("Only Integer Valid!", "\\d+"));
final Button validateBt = (Button) findViewById(R.id.validateBt);
validateBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// validate
validationEt.validate();
}
});
}
示例2: showDialog
import com.rengwuxian.materialedittext.MaterialEditText; //导入方法依赖的package包/类
private void showDialog(DialogType dialogType) {
View dialogView;
switch (dialogType) {
case JOIN_DIALOG:
dialogView = View.inflate(this, R.layout.dialog_join_party, null);
break;
case CREATE_DIALOG:
dialogView = View.inflate(this, R.layout.dialog_create_party, null);
break;
default:
return;
}
Dialog mockDialog = new Dialog(this, R.style.FullScreenDialogStyle);
mockDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mockDialog.setContentView(dialogView);
MaterialEditText partyTitle = mockDialog.findViewById(R.id.partyTitle);
MaterialEditText partyPassword = mockDialog.findViewById(R.id.partyPassword);
partyTitle.addValidator(new PartyTitleValidator());
partyPassword.addValidator(new PartyPasswordValidator());
mockDialog.findViewById(R.id.submitButton).setOnClickListener(c -> {
switch (dialogType) {
case JOIN_DIALOG:
if(!(partyTitle.validate() & partyPassword.validate())) return;
animateDialog(DialogAction.CLOSE, dialogType, dialogView, mockDialog);
getPresenter().joinParty(partyTitle.getText().toString(), partyPassword.getText().toString());
break;
case CREATE_DIALOG:
if(!(partyTitle.validate() & partyPassword.validate())) return;
animateDialog(DialogAction.CLOSE, dialogType, dialogView, mockDialog);
getPresenter().createParty(partyTitle.getText().toString(), partyPassword.getText().toString());
break;
}
});
mockDialog.findViewById(R.id.closeDialogButton).setOnClickListener(c ->
animateDialog(DialogAction.CLOSE, dialogType, dialogView, mockDialog));
mockDialog.setOnShowListener(dialogInterface ->
animateDialog(DialogAction.OPEN, dialogType, dialogView, null));
mockDialog.setOnKeyListener((dialogInterface, i, keyEvent) -> {
if (i == KeyEvent.KEYCODE_BACK) {
animateDialog(DialogAction.CLOSE, dialogType, dialogView, mockDialog);
return true;
}
return false;
});
mockDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mockDialog.show();
}