Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Improve alert function

$
0
0

I needed to display alerts in processing android so I got some code from another post and boiled it down to this

import android.app.AlertDialog;

String alertMessage;

void setup() {
  alertMessage = "This is the message";
  createAlert();
}

void createAlert() {
  runOnUiThread(new Runnable() {
    @ Override
      public void run() {
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
      alertDialog.setTitle("Alert");
      alertDialog.setMessage(alertMessage);
      alertDialog.setPositiveButton("OK", null);
      alertDialog.show();
    }
  }
  );
}

Which works great but now to display some text in an alert I have to change the alertMessage and then call the function, there must be a way to turn it into a function that takes in a string, something like this createAlert("This is the message"); but I cant figure out how to do it with the UiThread being inside the function.

Any advice?


Viewing all articles
Browse latest Browse all 941

Trending Articles