Android 登录时出错仍然提示但仍然登录
我正在开发一个移动应用程序,它有两种类型的用户 在我的php代码中,我为每个用户分隔了布尔值<客户的代码>成功,设计师的代码>成功1 当我按log in时,错误提示首先是成功菜单配置文件的快速意图 这是我从Android 登录时出错仍然提示但仍然登录,android,Android,我正在开发一个移动应用程序,它有两种类型的用户 在我的php代码中,我为每个用户分隔了布尔值成功,设计师的代码>成功1 当我按log in时,错误提示首先是成功菜单配置文件的快速意图 这是我从LoginRegister.java private ProgressBar loading; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
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);
}
});
}
私有进度条加载;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
最终的EditText用户LoginUserName=(EditText)findViewById(R.id.loginUser);
最终EditText userLoginPassword=(EditText)findViewById(R.id.loginPass);
最终按钮登录=(按钮)findViewById(R.id.buttonLogin);
最终按钮寄存器=(按钮)findViewById(R.id.buttonRegister);
loading=findViewById(R.id.loadinglogin);
//登录
Login.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
最终字符串username=userLoginUsername.getText().toString();
最终字符串密码=userLoginPassword.getText().toString();
如果(!username.isEmpty()&&!password.isEmpty()){
Login.setVisibility(View.GONE);
加载.setVisibility(视图.VISIBLE);
Response.Listener responseListener=新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONObject jsonResponse=新的JSONObject(响应);
boolean success=jsonResponse.getBoolean(“success”);
boolean success1=jsonResponse.getBoolean(“success1”);
//客户端登录
如果(成功){
//gikan sa php(绿色)到字符串sa android
字符串username=jsonResponse.getString(“用户名”);
String name=jsonResponse.getString(“name”);
String number=jsonResponse.getString(“number”);
stringgender=jsonResponse.getString(“gender”);
String address=jsonResponse.getString(“地址”);
字符串占用=jsonResponse.getString(“占用”);
String birth_date=jsonResponse.getString(“birth_date”);
String user_type=jsonResponse.getString(“user_type”);
意向意向=新意向(LoginRegister.this,ProfileActivity.class);
//从字符串到传递sa lain意图。
intent.putExtra(“用户名”,用户名);
意向。额外(“数字”,数字);
意向。额外(“名称”,名称);
意图。putExtra(“性别”,性别);
意向。额外(“地址”,地址);
意向。额外(“占领”,占领);
意图。putExtra(“出生日期”,出生日期);
intent.putExtra(“用户类型”,用户类型);
LoginRegister.this.startActivity(意图);
完成();
}否则{
AlertDialog.Builder=新建AlertDialog.Builder(LoginRegister.this);
setMessage(“登录失败!请提供有效的用户名和密码或连接到internet。”)
.setNegativeButton(“重试”,null)
.create()
.show();
Login.setVisibility(View.VISIBLE);
loading.setVisibility(View.GONE);
}
//设计师登录
如果(成功1){
String user_type=jsonResponse.getString(“user_type”);
意向意向=新意向(LoginRegister.this,ProfileActivity.class);
intent.putExtra(“用户类型”,用户类型);
LoginRegister.this.startActivity(意图);
完成();
}否则{
AlertDialog.Builder=新建AlertDialog.Builder(LoginRegister.this);
setMessage(“登录失败!请提供有效的用户名和密码或连接到internet。”)
.setNegativeButton(“重试”,null)
.create()
.show();
Login.setVisibility(View.VISIBLE);
loading.setVisibility(View.GONE);
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
};
LoginRequest LoginRequest=新的LoginRequest(用户名、密码、响应侦听器);
RequestQueue=Volley.newRequestQueue(LoginRegister.this);
添加(loginRequest);
}else if(username.isEmpty()){
setError(“请插入用户名”);
}else if(password.isEmpty()){
userLoginPassword.setError(“请输入密码”);
}
}
});
//登记册
Register.setOnC
//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 = ...
}
}
...