アプリケーションでログインダイアログを完了しようとしていますが、ダイアログの処理に問題があります。
3つのダイアログがあります。1つはログインダイアログとしてのAlertDialog、2つ目はprogressDialog、そしてエラーメッセージを表示するalertDialogです。これが私のコードです:
protected Dialog onCreateDialog(int id) {
switch (id) {
case KBConstants.DIALOG_LOGIN_ID:
TextView textUsername;
TextView textPassword;
TextView textSave;
// Here I build my Layout
...
// return dialog
return new AlertDialog.Builder(this).setTitle(R.string.login_title).setMessage(R.string.login_introduction).setView(loginLayout).setIcon(R.drawable.kreative_barometer_72x72)
.setPositiveButton(R.string.login_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final DialogInterface d = dialog;
if (checkBoxSave.isChecked()) {
setRememberLogin(true);
} else {
setRememberLogin(false);
}
waitConnect = ProgressDialog.show(KreativBarometerMainView.this, getString(R.string.login_connect_title), getString(R.string.login_connect_introduction), false, true);
Thread t1 = new Thread() {
public void run() {
Looper.prepare();
DataStruct dataStruct = null;
try {
dataStruct = SoapHandler.makeCall(SoapHashMap.CHECK_USER_LOGIN, mainService.getSoapMap(), editUsername.getText().toString(), editPassword.getText().toString(), null, null);
ServerMessageStruct sms = (ServerMessageStruct) dataStruct;
if (sms.getMsgType() == 1) {
mainService.setUserValidation(true);
setLogin(editUsername.getText().toString(), editPassword.getText().toString());
} else {
mainService.setUserValidation(false);
setLogin(null, null);
}
} catch (IOException ioe) {
mainService.setUserValidation(false);
setLogin(null, null);
} catch(XmlPullParserException xmlppe){
} finally{
if(!mainService.isUserValidated()){
waitConnect.dismiss();
showDialog(KBConstants.DIALOG_NO_LOGIN_USER_ID);
}
}
waitConnect.dismiss();
}
};
t1.start();
}
}).setNeutralButton(R.string.login_setup, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked setup so do some stuff */
startActivity(new Intent(packageContext, SettingView.class));
}
}).setNegativeButton(R.string.login_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
KreativBarometerMainView.this.finish();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
KreativBarometerMainView.this.finish();
}
}).create();
case KBConstants.DIALOG_NO_LOGIN_USER_ID:
return new AlertDialog.Builder(this).setMessage(R.string.login_info_error_user).setIcon(R.drawable.kreative_barometer_72x72).setTitle(R.string.login_error)
.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
showDialog(KBConstants.DIALOG_LOGIN_ID);
}
}).create();
}
return null;
}
ユーザーが「接続」(ポジティブボタン)をクリックすると、SOAP呼び出しが行われ、ユーザーデータを検証するWebサービスが使用されます。ユーザーが呼び出しが行われるのを待っている間、progressDialogが表示されて作業が示されます。呼び出しが行われた後、DIALOG_NO_LOGIN_USER_ID
ユーザーデータが有効でない場合はダイアログが表示されます。ユーザーは[OK]をクリックすると、ログインダイアログが再度表示されます。
ただし、DIALOG_NO_LOGIN_USER_IDダイアログは表示されません。スレッドの開始後にshowDialog()を呼び出そうとしましたが、スレッドの問題があります。ダイアログが表示されますが、検証の結果は無視されます。
誰かがダイアログを管理する方法を理解するのを手伝ってもらえますか?AlertDialogをログインダイアログとして使用するための、おそらく「より良い」解決策は他にありますか?
よろしく、htz