Solved

Updating text if a certain value is entered

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
word0 challenge 3 58
groovy example issue 10 66
Free Alternative to JIRA 4 55
Groovy:unable to resolve class error 2 28
Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

18 Experts available now in Live!

Get 1:1 Help Now