Answer the question
In order to leave comments, you need to log in
How to call a private method in Fragmente Android Studio?
It is not possible to call private void userLogin() in case 2. The application closes when the Login button is pressed.
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.register:
Intent reg = new Intent(getActivity(), Register.class);
startActivity(reg);
break;
case R.id.signIn:
userLogin();
break;
case R.id.forgotPassword:
Intent fP = new Intent(getActivity(), ForgotPassword.class);
startActivity(fP);
break;
}
}
public class ProfileFragment extends Fragment implements View.OnClickListener {
private TextView register, forgotPassword;
private EditText editTextEmail, editTextPassword;
private Button signIn;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
View v = inflater.inflate(R.layout.fragment_profile, container, false);
TextView register = (TextView) v.findViewById(R.id.register);
register.setOnClickListener(this);
Button signIn = (Button) v.findViewById(R.id.signIn);
signIn.setOnClickListener(this);
EditText editTextEmail = (EditText) v.findViewById(R.id.email);
EditText editTextPassword = (EditText) v.findViewById(R.id.password);
ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
TextView forgotPassword = (TextView) v.findViewById(R.id.forgotPassword);
forgotPassword.setOnClickListener(this);
return v;
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.register:
Intent reg = new Intent(getActivity(), Register.class);
startActivity(reg);
break;
case R.id.signIn:
userLogin();
break;
case R.id.forgotPassword:
Intent fP = new Intent(getActivity(), ForgotPassword.class);
startActivity(fP);
break;
}
}
private void userLogin() {
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if(email.isEmpty()){
editTextEmail.setError("Email обязателен!");
editTextEmail.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
editTextEmail.setError("Пожалуйста, введите корректный email!");
editTextEmail.requestFocus();
return;
}
if(password.isEmpty()){
editTextPassword.setError("Пароль обязателен!");
editTextPassword.requestFocus();
return;
}
if(password.length() < 6){
editTextPassword.setError("Пароль должен состоять минимум из 6 символов!");
editTextPassword.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
Answer the question
In order to leave comments, you need to log in
In the onCreateView method, instead of
EditText editTextEmail = (EditText) v.findViewById(R.id.email);
EditText editTextPassword = (EditText) v.findViewById(R.id.password);
editTextEmail = (EditText) v.findViewById(R.id.email);
editTextPassword = (EditText) v.findViewById(R.id.password);
Can't call private void userLogin() in case 2.
case R.id.signIn:
userLogin();
break;
The problem is not that you are not calling the method, since it is explicitly called here:
case R.id.signIn:
userLogin();
break;
The application closes when the Login button is pressed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question