Solved

Updating text if a certain value is entered

Posted on 2014-11-03
5
100 Views
Last Modified: 2014-11-03
Hi,

This is for an Android App.

I have some TextViews that I want to change the text of if a value in a certain textEdit is >1

I also have a textWatcher that looks for changed value in the textEdit.

only the tipTextView changes but nothing else. Any clue why?

I have made the references to the fields.
      tipTextView = (TextView) findViewById(R.id.tipTextView); 
      totalTextView = (TextView) findViewById(R.id.totalTextView);
      tipCustomTextView = (TextView) findViewById(R.id.tipCustomTextView);
      totalCustomTextView = (TextView) findViewById(R.id.totalCustomTextView);

Open in new window


I have created a method to update the text fields when value >1
   private void updateTextFields()
   {
	   
	   if (numGuests >1) {
		   tipTextView.setText("Split Tip");
		   totalTextView.setText("Split Total");
		   tipCustomTextView.setText("Split Tip");
		   totalCustomTextView.setText("Split Total");
	   }else
		   tipTextView.setText(tipText);
	   	   totalTextView.setText(totalText);
	       tipCustomTextView.setText(tipText);
	       totalCustomTextView.setText(totalText);
		   
   }
   

Open in new window

0
Comment
Question by:Computer Guy
  • 3
  • 2
5 Comments
 
LVL 3

Author Comment

by:Computer Guy
ID: 40418937
I noticed that if I make the text in the "else" part "SPLIT TIP" it will work if the value is >1 but not in the regular If part.
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 40418943
Ok, if I do this, it works - What is the best way to combine this as 1 statement?

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

	   }else
		   tipTextView.setText("Tip");

		   

   if (numGuests >1) {
	   totalTextView.setText("Split Total");

   }else
   	   totalTextView.setText("Total");

	   
}

Open in new window

0
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
ID: 40419101
Like this ? :

if (numGuests >1) {
		   tipTextView.setText("Split Tip");
           totalTextView.setText("Split Total");
	   }else{
		   tipTextView.setText("Tip");
           totalTextView.setText("Total");}

Open in new window

0
 
LVL 3

Author Comment

by:Computer Guy
ID: 40419125
Duh!! Ok I new that, I'm an idiot! I admit it :-) That's what I get for not getting a good night sleep!
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 40419140
Happens to us all at some point(s) ;)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 58
session migration servlets 2 35
Reading emails from an Android 3 39
Problem to Alipay 10 17
A short article about a problem I had getting the GPS LocationListener working.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

815 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

13 Experts available now in Live!

Get 1:1 Help Now