gpt4 book ai didi

android - Error on Logging in 仍然提示但还是登录

转载 作者:搜寻专家 更新时间:2023-11-01 09:21:55 25 4
gpt4 key购买 nike

我正在开发一个有两类用户的移动应用程序。

在我的 php 代码中,我为每个用户分离了 bool 值。客户为 success,造型师为 success1

当我按登录时,首先出现的错误提示是成功的菜单配置文件的快速 Intent 。

这是我在 LoginRegister.java

中的代码行
private ProgressBar loading;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);


final EditText userLoginUsername = (EditText) findViewById(R.id.loginUser);
final EditText userLoginPassword = (EditText) findViewById(R.id.loginPass);
final Button Login = (Button) findViewById(R.id.buttonLogin);
final Button Register = (Button) findViewById(R.id.buttonRegister);

loading = findViewById(R.id.loadinglogin);

//login
Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final String username = userLoginUsername.getText().toString();
final String password = userLoginPassword.getText().toString();

if(!username.isEmpty() && !password.isEmpty()) {
Login.setVisibility(View.GONE);
loading.setVisibility(View.VISIBLE);
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
boolean success1 = jsonResponse.getBoolean("success1");

//Client's Log in
if (success) {

//gikan sa php (green ones) to strings sa android
String username = jsonResponse.getString("username");
String name = jsonResponse.getString("name");
String number = jsonResponse.getString("number");
String gender = jsonResponse.getString("gender");
String address = jsonResponse.getString("address");
String occupation = jsonResponse.getString("occupation");
String birth_date = jsonResponse.getString("birth_date");
String user_type = jsonResponse.getString("user_type");

Intent intent = new Intent(LoginRegister.this, ProfileActivity.class);

//from strings to pass sa lain intents.
intent.putExtra("username",username);
intent.putExtra("number",number);
intent.putExtra("name", name);
intent.putExtra("gender", gender);
intent.putExtra("address", address);
intent.putExtra("occupation", occupation);
intent.putExtra("birthDate", birth_date);
intent.putExtra("userType", user_type);

LoginRegister.this.startActivity(intent);
finish();

} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginRegister.this);
builder.setMessage("Login Failed! Please provide valid username and password or connect to internet.")
.setNegativeButton("Retry", null)
.create()
.show();
Login.setVisibility(View.VISIBLE);
loading.setVisibility(View.GONE);

}

//Stylist's Log in
if(success1) {

String user_type = jsonResponse.getString("user_type");

Intent intent = new Intent(LoginRegister.this, ProfileActivity.class);

intent.putExtra("userType", user_type);

LoginRegister.this.startActivity(intent);
finish();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginRegister.this);
builder.setMessage("Login Failed! Please provide valid username and password or connect to internet.")
.setNegativeButton("Retry", null)
.create()
.show();
Login.setVisibility(View.VISIBLE);
loading.setVisibility(View.GONE);

}

} catch (JSONException e) {
e.printStackTrace();
}
}
};

LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(LoginRegister.this);
queue.add(loginRequest);
}else if(username.isEmpty() ){
userLoginUsername.setError("Please insert a username");
}else if(password.isEmpty()){
userLoginPassword.setError("Please put your password");
}

}
});

//register
Register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent Register = new Intent(LoginRegister.this, RegisterCustomerOrStylist.class);
LoginRegister.this.startActivity(Register);


}
});

}

PS 他们有来自不同表格的不同数据。我所做的是我有一个 if 条件,如果 success(客户端)的 bool 值是真的,它传递数据,它的其他是用于错误登录的 alertdialog。之后是 success1 (stylist) 的另一个 if 语句,它与 client 具有相同的逻辑。

最佳答案

如果简化,您的代码如下所示。

//Client's Log in
if (success) {
} else {
AlertDialog.Builder builder = ...
}

//Stylist's Log in
if(success1) {
} else {
AlertDialog.Builder builder
}

这意味着如果造型师尝试登录,将显示客户的登录阻止警报对话框,反之亦然。

因此,可能需要一个标志来检查是否存在任何成功。

boolean successAny = success || suucess1;

//Client's Log in
if (success) {
} else {
if (!successAny) {
AlertDialog.Builder builder = ...
}
}

...

注意。一个人既是客户又是造型师的案例不适用于此示例。

关于android - Error on Logging in 仍然提示但还是登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54387713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com