到目前为止,我的AlertDialog.Builder
始终在s.contains("")
时显示3次,而且我也无法找到原因。有人能指出我为什么或帮助我解决这个问题?谢谢。
HashMap postData = new HashMap();
postData.put("profileID", profile.getId());
AsyncClass task = new AsyncClass(LoginActivity.this, postData, new AsyncResponse() {
@Override
public void processFinish(String s) {
if (!s.equals("")) {
if (s.contains("Customer")) {
Intent in = new Intent(LoginActivity.this, MainActivity.class);
editor.putString("firstname", profile.getFirstName());
editor.putString("surname", profile.getLastName());
editor.putString("imageUrl", profile.getProfilePictureUri(200, 200).toString());
editor.putString("userRole", s);
editor.putString("userName", profile.getId());
editor.putString("name", profile.getName());
editor.apply();
startActivity(in);
finish();
} else if (s.contains("Wingman")) {
Intent in = new Intent(LoginActivity.this, WingmanMainActivity.class);
editor.putString("firstname", profile.getFirstName());
editor.putString("surname", profile.getLastName());
editor.putString("imageUrl", profile.getProfilePictureUri(200, 200).toString());
editor.putString("userRole", s);
editor.putString("userName", profile.getId());
editor.putString("name", profile.getName());
editor.apply();
startActivity(in);
finish();
}
} else if(s.equals("")) {
builderSingle = new AlertDialog.Builder(LoginActivity.this);
builderSingle.setTitle("Select a role: ");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(LoginActivity.this, android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("Customer");
arrayAdapter.add("Wingman");
builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
strName = arrayAdapter.getItem(which);
editor.putString("role", strName);
editor.apply();
if (String.valueOf(strName).contains("Wingman")) {
HashMap postData = new HashMap();
postData.put("userName", profile.getId());
postData.put("userRole", strName);
postData.put("userFirstname", profile.getFirstName());
postData.put("userLastname", profile.getLastName());
postData.put("userImage", profile.getProfilePictureUri(200,200).toString());
postData.put("isWingman","No");
AsyncClass task = new AsyncClass(LoginActivity.this, postData, true, new AsyncResponse() {
@Override
public void processFinish(String s) {
if (s.contains("success")) {
Intent in = new Intent(LoginActivity.this, WingmanMainActivity.class);
editor.putString("firstname", profile.getFirstName());
editor.putString("surname", profile.getLastName());
editor.putString("imageUrl", profile.getProfilePictureUri(200, 200).toString());
editor.putString("role", strName);
editor.putString("userName", profile.getId());
editor.putString("name", profile.getName());
editor.apply();
startActivity(in);
finish();
}
}
});
task.execute(getString(R.string.link) + "registerFB.php");
} else if (String.valueOf(strName).contains("Customer")) {
HashMap postData = new HashMap();
postData.put("userName", profile.getId());
postData.put("userRole", strName);
postData.put("userFirstname", profile.getFirstName());
postData.put("userLastname", profile.getLastName());
postData.put("userImage", profile.getProfilePictureUri(200,200).toString());
AsyncClass task = new AsyncClass(LoginActivity.this, postData, true, new AsyncResponse() {
@Override
public void processFinish(String s) {
if (s.contains("success")) {
Intent in = new Intent(LoginActivity.this, MainActivity.class);
editor.putString("firstname", profile.getFirstName());
editor.putString("surname", profile.getLastName());
editor.putString("imageUrl", profile.getProfilePictureUri(200, 200).toString());
editor.putString("role", strName);
editor.putString("userName", profile.getId());
editor.putString("name", profile.getName());
editor.apply();
startActivity(in);
finish();
}
}
});
task.execute(getString(R.string.link) + "registerFB.php");
}
}
});
builderSingle.show();
}
}
});
task.execute(getString(R.string.link) + "checkFB.php");