Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old December 26th, 2011, 05:55 AM   #1 (permalink)
New Member
 
Join Date: May 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default If statement Problem

Ok so im trying to make a app that opens a toast saying you are incorrect or correct although im having some trouble with my if statements can someone please tell me what the problem is






Code:
public class IfActivity extends Activity {
	Button GO;
	EditText TEXT;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		GO = (Button) findViewById(R.id.go);
		TEXT = (EditText) findViewById(R.id.Textin);

		GO.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				

				if ("hello".equals(TEXT)) {
					Toast andEggs = Toast.makeText(IfActivity.this,
							"PASSWORD IS CORRECT", Toast.LENGTH_SHORT);
					andEggs.show();
				} else {
					Toast andEggs = Toast.makeText(IfActivity.this,
							"PASSWORD IS INCORRECT", Toast.LENGTH_SHORT);
					andEggs.show();
				}

			}
		});

	}
}

mizzeeboy is offline  
Reply With Quote
Sponsors
Old December 27th, 2011, 05:18 AM   #2 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 308
 
Device(s): Samsung Galaxy Nexus
Thanks: 0
Thanked 52 Times in 51 Posts
Default

Your if's are built up correctly, but your comparison is incorrect. You are trying to compare the text "hello" with the EditText control TEXT. Instead you must compare the text "hello" with the text inside the EditText like this:
Code:
if ("hello".equals(TEXT.getText().toString())
__________________
Android: Personal Storage, Lars Monsen Facts(Norwegian)
miXer is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:20 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo