单击后会弹出一个对话框,询问用户注册信息。如果电子邮件是电子邮件,密码与确认密码匹配等,我想验证信息。我想使用下面提供的库。如果有更好的库或方法,请提供该方法或指向对我有帮助的内容的链接。尝试在Kotlin中创建用户注册页面
因此,我尝试遵循一些文档来添加验证,但是如果有多个EditText框,则在按应用程序中的注册按钮后,该应用程序将崩溃。该文档提到了有关回收站视图的内容。但不确定如何实现它。
implementation 'com.afollestad.material-dialogs:input:3.0.0-beta2'
implementation 'com.afollestad.material-dialogs:core:3.0.0-beta2'
register_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/name"
android:layout_margin="8dp"
android:hint="Name"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/r_email"
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/r_city"
android:hint="City"
android:inputType="text"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/r_password"
android:hint="Password"
android:inputType="textPassword"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/r_confirmPassword"
android:hint="Confirm password"
android:layout_margin="8dp"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
SigninActivity.kt
link_signup.setOnClickListener {
register()
}
link_forgot.setOnClickListener {
forgot()
}
}
private fun forgot() {
val forgot_layout = LayoutInflater.from(this@SignInActivity)
.inflate(R.layout.forgot_layout, null)
MaterialDialog(this).show {
title(text = "Recovery")
message(text = "Forgot your passsword?")
icon(R.drawable.ic_reset)
cancelable(true) // calls setCancelable on the underlying
dialog
cornerRadius(10f)
cornerRadius(res = R.dimen.my_corner_radius)
input(waitForPositiveButton = false, hint = "Email") {
dialog, text ->
val inputField = dialog.getInputField()
val isValid = text.startsWith("a", true)
inputField?.error = if (isValid) null else "Must be a
valid email!"
dialog.setActionButtonEnabled(WhichButton.POSITIVE,
isValid)
}
positiveButton(text = "Submit")
}
}
private fun register() {
MaterialDialog(this).show {
title(text = "Create an account")
message(text = "Please fill out the information below?")
customView(R.layout.register_layout, scrollable = true)
icon(R.drawable.ic_user)
cancelable(true) // calls setCancelable on the underlying
dialog
cornerRadius(10f)
cornerRadius(res = R.dimen.my_corner_radius)
positiveButton(text = "submit")
}
如上所述,我希望能够检查多个EditText框的多个复选框。