Solved

Updating Text Issue

Posted on 2014-11-02
3
95 Views
Last Modified: 2014-11-02
Hi,

I have a tip calculator app in Android - I have coded it so I have the option to split the total and tip by x number of guests.

I have a textview with the default text of "Tip". If the number of guests changes - I want the text to be "Split Tip".

In my app, I have a textWatcher

   
private TextWatcher numGuestTextWatcher = new TextWatcher() 
   {
      @Override
      public void onTextChanged(CharSequence s, int start, 
         int before, int count) 
      {         
         // convert billEditText's text to a double
         try
         {
            numGuests = Integer.parseInt(s.toString());
         } // end try
         catch (NumberFormatException e)
         {
            numGuests = 1; // default if an exception occurs
         } // end catch 
         updateTextFields();
      } //

Open in new window

      
Then the updateTextFields method:
        
	     private void updateTextFields()
   {
	   if (numGuests > 1) {
		   tipTextView.append("Split Tip");
	   }
   }

Open in new window

 
 But when I change the value back to 1, the default text does not change back to "Tip" which is what I set the default string text to.

Any clue why?
0
Comment
Question by:Computer Guy
  • 2
3 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 40418227
You don't have any code that fires when numGuests is less than or equal to 1. If you put an else block in that updateTextFields() method, you should be able to get the behavior you're looking for.
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 40418372
Like this:

{
         if (numGuests > 1) {
               tipTextView.append("Split Tip");
else
tipTextView.append("Tip");

         }
   }
0
 
LVL 14

Accepted Solution

by:
CPColin earned 500 total points
ID: 40418374
That won't compile. The else has to be after the end of the if block.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Understanding mobile browsers 9 84
hibernate example using maven 12 56
ejb wildfly example 2 17
JAVA API design with micro service cloud in mind 1 43
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
If your app took Google’s lash recently, here are the 5 most likely reasons.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question