Computer Guy
asked on
Updating Text Issue
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
Then the updateTextFields method:
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?
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();
} //
Then the updateTextFields method:
private void updateTextFields()
{
if (numGuests > 1) {
tipTextView.append("Split Tip");
}
}
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?
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.
ASKER
Like this:
{
if (numGuests > 1) {
tipTextView.append("Split Tip");
else
tipTextView.append("Tip");
}
}
{
if (numGuests > 1) {
tipTextView.append("Split Tip");
else
tipTextView.append("Tip");
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.