In VB to use an alert box you write:
Response=Msgbox("Click YES to continue, NO to Abort",vbyesno)
If response=vbyes...do something
In Java we have to write yards more code to do this. What I wanted to write was a utility function that could be called from anywhere and return a response. I wrote:
protected static boolean Response=false;
public boolean CreateAlert(String AlertMessage){
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage(AlertMessage);
alertbox.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Response=true;
}
});
alertbox.setNegativeButton("NO" , new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
Response=false;
}
});
alertbox.show();
return Response;
However, I could not move it to a different class because AlertDialogBuilder needs a this which presumably means I need to pass a context variable from another class. A Message Box is an almost essential component of interactive forms, and all I want is to add 1 line of code for each time I open a Message Box...there must be a way!!