AlertDialog使用buttonLlick动态调用下一个对话框,其中包含从LinkedHashMap读取的数据

时间:2014-04-29 09:16:45

标签: java android

我想在LinkedHashMap上执行类似getNext()调用的操作,并将数据发送到create_dialog_method。我读到了在hashmap上使用Iterator和一些保持下一个位置轨迹的计数器。我不确定如何以编码方式进行。

以下是对话的活动: 公共类QuestionsActivity扩展了Activity {

Map<String, Boolean> question_map = new LinkedHashMap<String, Boolean>();


//ArrayList<Questions> question_array = new ArrayList<Metrics>();

int counter = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_layout);

    //false = call showRiskEvaluationDialog() on button NO
    //true  = call showRiskEvaluationDialog() on button YES
    question_map.put("8. Question8?", false);
    question_map.put("7. Question7?", false);
    question_map.put("6. Question6?", false);
    question_map.put("5. Question5?", false);
    question_map.put("4. Question4?", false);
    question_map.put("3. Question3?", false);
    question_map.put("2. Question2?", false);
    question_map.put("1. Question1?", false);


    create_dialog_method("asd2313", false);


    // For loop to extract a question and identifier from the Map


    //for (Entry<String, Boolean> entry : question_map.entrySet()){
    //   create_dialog_method(entry.getKey(), entry.getValue());
    //}//end for


}//end onCreate()




/**
 * Method for creating a dialog window that show question and two buttons.
 * @param question_param
 * @param identifier
 */
public void create_dialog_method(String question_param, final boolean identifier) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Title");
    alert.setMessage(question_param);

    alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialog, int whichButton) {

          if (identifier)

              showRiskEvaluationDialog();
          else 

              //**********HERE IS THE PROBLEM********
              if (identifier == false);

              for (Entry<String, Boolean> entry:  question_map.entrySet()){
                  create_dialog_method(entry.getKey(),entry.getValue());
                  break;

              }


             Toast.makeText(getApplicationContext(), "Saved",
                   Toast.LENGTH_SHORT).show();

       }
    });

    alert.setNegativeButton("NO", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialog, int whichButton) {

          if (identifier)
              Toast.makeText(getApplicationContext(), "Saved",
                      Toast.LENGTH_SHORT).show();
          else

          showRiskEvaluationDialog();
       }
    });
    alert.show();
 }

0 个答案:

没有答案