From 05637473dbb9a1dbea2995949ab28ab50f4bbb92 Mon Sep 17 00:00:00 2001 From: Ali Date: Wed, 12 Jun 2019 15:14:46 +0500 Subject: [PATCH] Updated the SimpleFragment.java I refactored the code of showing Ratings to the mobile screen . This code is just one line code and does not need to create another variable to do the task. --- .../android/fragmentexample/SimpleFragment.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/FragmentExample1_challenge/app/src/main/java/com/example/android/fragmentexample/SimpleFragment.java b/FragmentExample1_challenge/app/src/main/java/com/example/android/fragmentexample/SimpleFragment.java index 5901e89..cc7c00f 100644 --- a/FragmentExample1_challenge/app/src/main/java/com/example/android/fragmentexample/SimpleFragment.java +++ b/FragmentExample1_challenge/app/src/main/java/com/example/android/fragmentexample/SimpleFragment.java @@ -88,11 +88,17 @@ public void onCheckedChanged(RadioGroup group, @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { - // Get rating and show Toast with rating. - String myRating = (getString(R.string.my_rating) + - String.valueOf(ratingBar.getRating())); - Toast.makeText(getContext(), myRating, - Toast.LENGTH_SHORT).show(); + // Get rating and show Toast with rating(Old). +// String myRating = (getString(R.string.my_rating) + +// String.valueOf(ratingBar.getRating())); +// Toast.makeText(getContext(), myRating, +// Toast.LENGTH_SHORT).show(); + + // Get rating and show Toast with rating(New). + // instead of above code you can write only the following as the 'rating' parameter is there to complete your needs + Toast.makeText(getContext(), rating, +// Toast.LENGTH_SHORT).show(); + } });