0

i want to generate number of editbox according to the for loop, with a button that has to invoke method which will process the userinput data into editbox.

as far as i know i can not use the alert dialogue boxes as they are async and will not wait for the user response, i might use the method mentioned above and see the behaviour. and suggestion and advice is required. the code below may give some more idea.

for(int x=0;x<vars.size();x++)
    {
        String get_var=vars.get(x).toString();//get the first item from array
        replace(get_var,temp_t);//send the get_var to replace method
    }

the replace method idea is

replace(String get_var,String temp_t)
{
 String y=(user input from the textbox, which has to be created dynamically)
if(button pressed) //created dynamically
process(y,temp_t)
}

please suggest if there is any other work around better then what i think should work like eliminating the button and processing directly [update]

    for(int x=0;x<vars.size();x++)
    {
        String get_var=vars.get(x).toString();
        get_vals_for_xy(get_var, temp_t);
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}//end of oncreate method

public void get_vals_for_xy(String get_var,String[][] temp_t) {
    System.out.println("value of get_var is " + get_var);
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    final EditText edittext = new EditText(this);
    alert.setMessage("value is"+get_var);
    alert.setTitle("Title");

    alert.setView(edittext);

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

            String to_replace = edittext.getText().toString();
            show(to_replace);
            Toast.makeText(AssignValandFacts.this, to_replace, Toast.LENGTH_SHORT).show();
        }
    });

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

        }
    });

    alert.show();


}
Shahensha Khan
  • 265
  • 1
  • 19

1 Answers1

0

You can prompt a dialog for each item in the for loop and get user input

boolean userResponseReceived=false;
//create a dialog
Dialog dialog=new Dialog(context);
//set dialog content view
//I just assume you have a button in dialog that says OK
Button okButton=(Button)dialog.findViewById(R.id.btnId);
okButton.setOnClickListener(new View.OnclickListener{
     @Override
     public void onClick(View v){
         //userResponseRecieved is a instance variable
         userResponseReceived=true;
     }
});
for(int x=0;x<vars.size();x++){
    //make a while loop to hold the for loop while user inserts data
    //make a dialog box and handle user input
    dialog.show();
    while(!userResponseReceived){}
    //continue with the for loop
    dialog.dismiss();
    userResponseReceived=false;
}
Malith Lakshan
  • 762
  • 6
  • 12
  • thats what i also know but how to do it, i have used the prompts and the logic provded above but thats not working – Shahensha Khan May 24 '16 at 09:22
  • i updated the code, can u please give me a hint where to put the boolean. i am trying here n there but same result. it not stopping in loop – Shahensha Khan May 24 '16 at 09:57
  • Put the boolean at the very top of the class so that the onClickListener of the dialog button can access it. – Malith Lakshan May 24 '16 at 10:02
  • Suppose it isn't an infite loop. But the app freezes at the while loop. Where exaclty do you call this fo loop. onCreate or on click event? Update your question with that full method. – Malith Lakshan May 24 '16 at 11:42