Solved

Updating Text Issue

Posted on 2014-11-02
3
93 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group texting 7 49
Receipt Printer for web based app 3 33
tomcat not starting 6 32
MySqlDump not dumping triggers 1 18
Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now