1

I have an android studio activity that buffers a long string and then outputs the entire string to the phone screen when done. I'm using the following to buffer each line of my report using format() to format columns so they line up correctly left justified:

buffer.append(String.format("%-5s %-8s- %-8s%n",substring(startDay,2,5), lessonEndTime, ENDOFDAY));

After buffering the entire report I send it to the phone screen using the following method:

   public void showMessage(String title, String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.show();
        return;
    }

The output is in a variable spaced font which messes up the spacing of the columns. Is there a way to change the font that AlertDialog.Builder uses to a monospace font?

Doug White
  • 11
  • 3
  • So... is the question "how do I set the font for the console in Android Studio"? Because that's not a programming question per se, more a question on where a setting is in software you use (probably one that people here can answer, but also one that people on superuser can probably answer *even better*) – Mike 'Pomax' Kamermans Oct 02 '17 at 23:39
  • You must not have read my question very carefully, but just to clarify, I am coding a program in java using Android Studio. I am outputting a buffered string formatted with format() using the parameter %-8s which formats a string value left justified in a space of 8 characters. However, I havent set any kind of specific font anywhere in my code, but what gets outputted is in a variable spaced font which makes the columns of each line begin and end in different places (they don't line up.) What I want to know is how can I change the output using java code to a monospaced font. – Doug White Oct 03 '17 at 18:42
  • Right, so based on "what gets outputted is in a variable spaced font" the question is: output **where**? In the Android Studio console? If so, then see my original comment. If not: please update your post to explain where that output is getting written to (log file? your UI? right now that information is missing which means an appropriate answer cannot be given) – Mike 'Pomax' Kamermans Oct 03 '17 at 19:50
  • I edited my original question in hopes of making it clearer and more specific. I hope it helps you help me. I'm pretty new to this. – Doug White Oct 04 '17 at 16:39
  • Looking at the [Android API docs](https://developer.android.com/reference/android/app/AlertDialog.Builder.html#AlertDialog.Builder(android.content.Context,%20int)), is the parent context (the `this` argument) to the builder set up to use a monospace font? If not, you might need to show a bit more code to show what the actual class hierarchy is for the object you're calling showMessage in. – Mike 'Pomax' Kamermans Oct 04 '17 at 20:02
  • on that note, you might want to look into how to override the default alert dialog theme, which has been asked before in https://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog (and possibly others) – Mike 'Pomax' Kamermans Oct 04 '17 at 20:05

0 Answers0