问题描述
Android Studio: 您好,我在底部导航了三个片段,其中一个片段是一个LoginFragment。我想做的是,用用户个人资料替换登录片段,以便登录后无法再访问登录片段。我该怎么办? (登录片段称为“ RegisterFragment”)
public class RegisterFragment extends Fragment {
EditText emaiL;
EditText passworD;
Button buttonLogin;
TextView textviewRegister;
ProgressBar progressBar;
FirebaseAuth fAuth;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.fragment_register,container,false);
//initialize your view here for use view.findViewById("your view id")
progressBar = (ProgressBar) v.findViewById(R.id.progressBar2);
fAuth = FirebaseAuth.getInstance();
emaiL = (EditText) v.findViewById(R.id.email);
passworD = (EditText) v.findViewById(R.id.password);
buttonLogin = (Button) v.findViewById(R.id.button_login);
textviewRegister = (TextView) v.findViewById(R.id.textview_register);
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String eMail = emaiL.getText().toString().trim();
String passWord = passworD.getText().toString().trim();
if (TextUtils.isEmpty(eMail)) {
emaiL.setError("Email is required");
return;
}
if (TextUtils.isEmpty(passWord)) {
passworD.setError("Password is required");
return;
}
if (passWord.length() < 6) {
passworD.setError("Password to short");
return;
}
progressBar.setVisibility(View.VISIBLE);
fAuth.signInWithEmailAndPassword(eMail,passWord).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful());
Intent loginIntent = new Intent (getActivity().getApplicationContext(),LoginActivity.class);
startActivity(loginIntent);
}
});
}
});
textviewRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registerIntent = new Intent (getActivity().getApplicationContext(),LoginActivity.class);
startActivity(registerIntent);
}
});
return v;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)