AlertDialog.Builder builderSingle = new AlertDialog.Builder(Questionnaire.this);
builderSingle.setIcon(R.drawable.seal_catanauan);
builderSingle.setTitle("Select survey to use: ");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
Questionnaire.this,
android.R.layout.select_dialog_singlechoice);
// arrayAdapter.add("Hardik");
// arrayAdapter.add("Archit");
// arrayAdapter.add("Jignesh");
// arrayAdapter.add("Umang");
// arrayAdapter.add("Gatti");
System.out.println(jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
// Get JSON object
JSONObject obj = (JSONObject) jsonArray.get(i);
arrayAdapter.add("(" + obj.get("sysid").toString() + ")" + obj.get("surveytitle").toString());
// DB QueryValues Object to insert into SQLite
//controller.insertusername(obj.get("username").toString(),obj.get("password").toString(),obj.get("fname").toString(),obj.get("mname").toString(),obj.get("lname").toString(),obj.get("suffix").toString(),obj.get("status").toString());
}
builderSingle.setCancelable(false);
builderSingle.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Intent todashboard = new Intent(getApplicationContext(), Dashboard.class);
startActivity(todashboard);
finish();
}
});
builderSingle.setAdapter(
arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
AlertDialog.Builder builderInner = new AlertDialog.Builder(
Questionnaire.this);
String surveyid = strName.split("[\\(\\)]")[1];
builderInner.setMessage(strName.split("[\\(\\)]")[2]);
builderInner.setTitle("Your Selected Survey is");
builderInner.setCancelable(false);
builderInner.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
builderInner.setNegativeButton(
"Back",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// Questionnaire.super.onBackPressed();
}
});
builderInner.show();
}
});
builderSingle.show();
我尝试使用
dialog.dismiss();
这会关闭两个对话框。
如何仅关闭一个对话框并返回上一个对话框?
当我单击“后退”按钮并且我想返回上一个builderInner
对话框时,我想关闭当前对话框builderSingle
。
我尝试使用
dialog.dismiss();
这会关闭两个对话框。
如何仅关闭一个对话框并返回上一个对话框?
答案 0 :(得分:0)
我将builderSingle更改为:
final AlertDialog.Builder builderSingle = new AlertDialog.Builder(Questionnaire.this);
现在最终,然后在我的
中builderInner.setNegativeButton(
"Back",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
builderSingle.show();//added this line
//Questionnaire.super.onBackPressed();
}
});
我在后面的按钮点击中添加了 builderSingle.show(); 这一行。
我只是担心在将builderSingle设置为final后我可能会导致一些我不知道的异常。
随意更新答案以使其正确。截至目前,它正在按预期工作