Solved

Updating text if a certain value is entered

Posted on 2014-11-03
5
99 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
A short article about a problem I had getting the GPS LocationListener working.
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.

863 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

21 Experts available now in Live!

Get 1:1 Help Now