input from user using for loop and prompt dialogue box shows different behaviour

时光毁灭记忆、已成空白 提交于 2019-12-12 04:26:12

问题


i used the code below to get user input in android app. it runs fine but what i found after several attempts is that. the method below is called from a for loop to get different values.

  1. The code takes input in reverse order i.e it has to take value for x and then y. while on the app i am asked to enter value of y and then x.

  2. it doesnot wait for the user input it shows the dialogue box but keeps on running the whole program. as when i enter any value doesnt make any changes as it has to do.

what i believe is that the reverse order of dialogue boxes is also from the same reason that the second dialogue box overlaps the first one.

how do i make it stop unless user enter any data and then move forward? also when i remove final from the editbox in the code, it gives error the please use remove view because this child already has a parent etc.

code is provided below

void var_init(String to_match,String[][] temp) {

    String t_match=to_match;
//problem in the below line


    AlertDialog.Builder builder = new AlertDialog.Builder(RuleEngine.this);
    builder.setTitle("Enter Value for"+t_match);

// Set up the input
    final EditText input = new EditText(RuleEngine.this);

    builder.setView(input);

// Set up the buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
           t_replace = input.getText().toString();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();

回答1:


Its becasue the dialogue boxes overlaps each other with every iteration. in reality the x is coming first but overlapped by the y dialogue box. an as async behaviour try to find other way around.




回答2:


You can call this method from your OnClick methods of positive or negative button i.e when the user presses ok or cancel button, then check your condition to show another dialog or not and call the function which is generating the dialog.



来源:https://stackoverflow.com/questions/37403552/input-from-user-using-for-loop-and-prompt-dialogue-box-shows-different-behaviour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!