From c47f38bbeee30e3cda4058e6c27d0b2cc6597730 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Wed, 1 Mar 2017 19:36:57 -0600 Subject: [PATCH] Fixed toast location for readability --- .../wbrawner/numberguess/MainActivity.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/wbrawner/numberguess/MainActivity.java b/app/src/main/java/com/wbrawner/numberguess/MainActivity.java index 55edf23..4f996c7 100644 --- a/app/src/main/java/com/wbrawner/numberguess/MainActivity.java +++ b/app/src/main/java/com/wbrawner/numberguess/MainActivity.java @@ -4,6 +4,7 @@ import android.app.DialogFragment; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.Gravity; import android.view.View; import android.widget.EditText; import android.widget.TextView; @@ -52,18 +53,22 @@ public class MainActivity extends AppCompatActivity public void setResponse(Map response) { CharSequence text; + Context context = getApplicationContext(); + int duration = Toast.LENGTH_SHORT; + Toast toast = Toast.makeText(context, null, duration); if (response.get("code").equals("correct")) { String popup = String.format(getString(R.string.correct_answer), response.get("count")); text = getString(R.string.game_over); gameOver(popup); - } else if (response.get("code").equals("too_big")) { - text = getString(R.string.too_big); } else { - text = getString(R.string.too_small); - } - Context context = getApplicationContext(); - int duration = Toast.LENGTH_SHORT; - Toast toast = Toast.makeText(context, text, duration); + toast.setGravity(Gravity.CENTER, 0, 0); + if (response.get("code").equals("too_big")) { + text = getString(R.string.too_big); + } else { + text = getString(R.string.too_small); + } + } + toast.setText(text); toast.show(); }