Solved

Updating text if a certain value is entered

Posted on 2014-11-03
5
102 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
airdroid android app 5 61
a successful app 7 29
Office 365 Controls 3 22
Overriding a method 3 14
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

751 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