Solved

Updating Text Issue

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 39
login jsp example 24 51
jsp insert to database example 2 26
Selenium docs api java index 3 19
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
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

821 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