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

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);


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

2 Answers

  1. Lance- Reply


    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. Larry- Reply


    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>