【发布时间】:2021-04-20 10:41:15
【问题描述】:
我在这里面临的问题是,每当我点击注册按钮时,它应该将我重定向到下一页,但这里没有发生。当我点击注册按钮时没有任何反应;它不会将我重定向到下一页页面..即使没有错误..我也尝试了各种方法仍然无法正常工作。但问题是我已经向我的 xml 文件添加了验证。这是我在重定向页面意图时遇到问题的原因吗?非常感谢任何帮助
这是我的 new_user_register.java 文件
public class new_user_register extends AppCompatActivity {
EditText name1;
EditText email1;
EditText usname1;
EditText password1;
Button register;
ToastManager toastManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_user_register);
name1 = (EditText) findViewById(R.id.name1);
email1 = (EditText) findViewById(R.id.email1);
usname1 = (EditText) findViewById(R.id.usname1);
password1 = (EditText) findViewById(R.id.password1);
register = (Button) findViewById(R.id.registerr);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name1.getText().toString().trim();
String EMAIL = email1.getText().toString().trim();
String username = usname1.getText().toString().trim();
String password = password1.getText().toString().trim();
String emailPattern = "^[a-zA-Z0-9+_.-]{3,32}+@[a-zA-Z0-9.-]{2,32}+$";
boolean isAtLeastOneFieldNotEmpty = !NAME.isEmpty()
|| !EMAIL.isEmpty()
|| !username.isEmpty()
|| !password.isEmpty();
toastManager = new ToastManager(new_user_register.this);
// You have 5 registration fields that users must fill up.
final int totalRegistrationField = 5;
// This will increase by 1 when a field is valid
int validRegistrationFieldCount = 0;
if (isAtLeastOneFieldNotEmpty) {
// NAME VALIDATION
if (NAME.isEmpty()) {
toastManager.addToast("ENTER NAME", ToastManager.Duration.LENGTH_SHORT);
} else if (!((NAME.length() > 3) && (NAME.length() < 15))) {
toastManager.addToast("NAME IS TOO SHORT.IT MUST BE BETWEEN 3-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else if (!NAME.matches("[a-zA-Z ]+")) {
toastManager.addToast("ONLY ALPHABETS ALLOWED", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// EMAIL VALIDATION
if (EMAIL.isEmpty()) {
toastManager.addToast("ENTER EMAIL-ID", ToastManager.Duration.LENGTH_SHORT);
} else if (!(EMAIL.matches(emailPattern))) {
toastManager.addToast("INVALID EMAIL", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// USERNAME VALIDATION
if (username.isEmpty()) {
toastManager.addToast("ENTER USERNAME", ToastManager.Duration.LENGTH_SHORT);
} else if (!((username.length() > 6) && (username.length() < 15))) {
toastManager.addToast("USERNAME IS TOO SHORT.IT MUST BE BETWEEN 6-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// PASSWORD VALIDATION
if (password.isEmpty()) {
toastManager.addToast("ENTER PASSWORD", ToastManager.Duration.LENGTH_SHORT);
} else if (!((password.length() > 6) && (password.length() < 15))) {
toastManager.addToast("PASSWORD IS TOO SHORT.IT MUST BE BETWEEN 6-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
} else {
toastManager.addToast("ALL FIELDS ARE COMPULSORY", ToastManager.Duration.LENGTH_SHORT);
}
if (validRegistrationFieldCount != totalRegistrationField) {
// Finally show all toast all screen
toastManager.show();
} else {
Intent i = new Intent(new_user_register.this, bottom_nav.class);
startActivity(i);
}
}
});
}
}
这是我的 new_user_register.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".loginpage"
android:background="@drawable/ic_launcher_background">
<TextView
android:layout_width="216dp"
android:layout_height="68dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginEnd="128dp"
android:layout_marginBottom="561dp"
android:text="NEW USER REGISTRATION"
android:textColor="@color/black"
android:textSize="25dp"
android:textStyle="bold|italic"
android:typeface="sans" />
<TextView
android:id="@+id/textView"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="207dp"
android:layout_marginBottom="277dp"
android:drawableLeft="@drawable/username_foreground"
android:text="USERNAME"
android:textColor="@color/Purple"
android:textSize="20dp" />
<TextView
android:id="@+id/name"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="256dp"
android:layout_marginBottom="501dp"
android:drawableLeft="@drawable/username_foreground"
android:text="NAME"
android:textColor="@color/Purple"
android:textSize="20dp" />
<EditText
android:id="@+id/name1"
android:layout_width="291dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="80dp"
android:layout_marginBottom="434dp"
android:hint="ENTER NAME" />
<TextView
android:id="@+id/email"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="229dp"
android:layout_marginBottom="386dp"
android:drawableLeft="@drawable/password_foreground"
android:text="EMAIL ID"
android:textColor="@color/Purple"
android:textSize="20dp" />
<EditText
android:id="@+id/email1"
android:layout_width="289dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="87dp"
android:layout_marginBottom="326dp"
android:hint="ENTER EMAIL ID" />
<EditText
android:id="@+id/usname1"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="85dp"
android:layout_marginBottom="220dp"
android:hint="ENTER USERNAME" />
<TextView
android:id="@+id/t3"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="184dp"
android:layout_marginBottom="170dp"
android:drawableLeft="@drawable/password_foreground"
android:text="PASSWORD"
android:textColor="@color/Purple"
android:textSize="20dp" />
<EditText
android:id="@+id/password1"
android:layout_width="286dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="88dp"
android:layout_marginBottom="113dp"
android:hint="ENTER PASSWORD" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="525dp"
android:src="@drawable/imaagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="408dp"
android:src="@drawable/image" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="292dp"
android:src="@drawable/iimagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="176dp"
android:src="@drawable/imagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="61dp"
android:src="@drawable/imageee" />
<Button
android:id="@+id/registerr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="210dp"
android:layout_marginBottom="43dp"
android:background="@android:color/transparent"
android:text="REGISTER"
android:textColor="@color/Purple"
android:textSize="25dp" />
</RelativeLayout>
【问题讨论】:
-
是的。我的验证是正确的。它不会引起任何问题
-
只是我的页面没有达到预期
-
Intent i = new Intent(new_user_register.this, bottom_nav.class); startActivity(i);
-
我正在准备页面
标签: android android-studio android-layout android-fragments