Displaying multiple lines of text and variables in an AlertDialog using setMessage()

You can do something like this

String alert1 = "No. of attempts: " + counter;
String alert2 = "No. of wins: " + counterpos;
String alert3 = "No. of losses: " + counterneg;
alertDialog.setMessage(alert1 +"\n"+ alert2 +"\n"+ alert3);   

You could just create one string of everything you want to show and add "\n" where you'd like the line breaks to be.

alertDialog.setMessage("No. of attempts: " + counter + "\n" + 
            "No. of wins: " + counterpos + "\n" + 
            "No. of losses: " + counterneg);

Or even better to use a StringBuilder:

StringBuilder sb = new StringBuilder();
sb.append("No. of attempts: " + counter);
sb.append("\n");
sb.append("No. of wins: " + counterpos);
sb.append("\n");
sb.append("No. of losses: " + counterneg);
alertDialog.setMessage(sb.toString());

And the best way to do it would be to extract the static texts into a string resource (in the strings.xml file). Use the %d (or %s if you want to insert strings rather than ints) to get the dynamic values in the right places:

<string name="alert_message">No. of attempts: %1$d\nNo. of wins: %2$d\nNo. of losses: %3$d</string>

And then in code:

String message = getString(R.string.alert_message, counter, counterpos, counterneg);
alertDialog.setMessage(message);

You can also insert newlines directly in the strings.xml file:

<string name="my_string_text">This would revert your progress.\n\n Are you sure you want to proceed?</string>