Я новичок в комитете, и у меня есть проблемы с моим кодом, потому что я использую TextInputLayout и хочу, чтобы мой Пароль и Подтверждение пароля были проверены, но что бы я ни делал, это все равно вызывает проблемы для его исправления.
Вот мой Activity_register.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".Register">
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_RegPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:errorEnabled="true"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_RegCfmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/text_input_RegPassword"
app:errorEnabled="true"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm Password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="101dp"
android:text="Register"
android:onClick="Reg"/>
</LinearLayout>
, и это мой Register.java
, потому что я пытался использовать equals, но это не сработает, потому что когда я хочу набрать .getText
, это просто неверно
public class Register extends AppCompatActivity {
private TextInputLayout textInputRegPassword;
private TextInputLayout textInputRegCfmPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.activity_register);
textInputRegPassword = findViewById(R.id.text_input_RegPassword);
textInputRegCfmPassword = findViewById(R.id.text_input_RegCfmPassword);
}
private boolean RegisterPassword(){
String userReg = textInputRegPassword.getEditText().getText().toString().trim();
if(userReg.isEmpty()){
textInputRegPassword.setError("Enter Password");
return false;
} else {
textInputRegPassword.setError(null);
return true;
}
}
private boolean RegisterCfmPassword(){
String userReg = textInputRegCfmPassword.getEditText().getText().toString().trim();
if(userReg.isEmpty()){
textInputRegCfmPassword.setError("Enter Password");
return false;
} else {
textInputRegCfmPassword.setError(null);
return true;
}
}
public void Reg(View v){
if(!RegisterPassword() | !RegisterCfmPassword() ){
return;
}
}
}
Отредактировано: я хочу, чтобы мой пароль и подтверждение пароля подтвердили, что оба они одинаковы, и когда я нажимаю кнопку, он просто вылетает
private boolean Verify(){
if(CfmPassword.getText().toString().equals(Password.getText().toString())){
return true;
} else{
textInputRegCfmPassword.setError("Password Do Not Match");
return false;
}
}
public void Reg(View v){
if(!RegisterPassword() | !RegisterCfmPassword() | !Verify() ){
return;
}
}