Apps If statement Problem

mizzeeboy

Lurker
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();
				}

			}
		});

	}
}
 

miXer

Android Enthusiast
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())
 
Top