Android : Is possible to stop process while alert dialog finish its work?

on Monday, February 16, 2015


This is my method



public void getValues() {
alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = this.getLayoutInflater();
alertDialog.setView(inflater.inflate(R.layout.custom_layout, null));

alertDialog.setCancelable(false);

alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
field1 = (EditText)((Dialog) dialog).findViewById(R.id.field1);
field2 = (EditText)((Dialog) dialog).findViewById(R.id.field2);
errorMsg = (TextView)((Dialog) dialog).findViewById(R.id.login_error);
insert();
}
});

/* When negative (No/cancel) button is clicked*/
alertDialog.setNegativeButton("Back", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel(); // Your custom code
}
});
alertDialog.show();
}


I need this method to create an input dialog that get the values that I need to check in my database.


These method work with this code



MyClass object = createObject();
while(!checkDB(object))
{
//Alert Dialog
getValues();
}


Well, createObject() get some information in another part of code and create an object from class MyClass. checkDB search the object in my database;


My logic is: if the object that I search don't exists I will create it with the AlertDialog (method getValues() that with method insert() insert the new object in DB).


The problem is that if I use a while procedure, my AlertDialog won't create and so !checkDB(object) is always false!


How can I use this alertDialog in the while?


Thanks for answer


0 comments:

Post a Comment