Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating text if a certain value is entered

Posted on 2014-11-03
5
Medium Priority
?
107 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 17

Accepted Solution

by:
krakatoa earned 2000 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 17

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

963 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