tags:

views:

201

answers:

5

This should be simple, but I have tried if statements checking for null values and also ones checking the .length of it:

EditText marketValLow = (EditText) findViewById(R.id.marketValLow);
            EditText marketValHigh = (EditText) findViewById(R.id.marketValHigh);
            if (marketValLow.getText().length() != 0 && marketValHigh.getText().length() != 0) {
                Intent intent = new Intent();
                intent.setClass(v.getContext(), CurrentlyOwe.class);
                startActivity(intent);
            } else {
                Toast.makeText(CurrentMarketValue.this, "You need to enter a high AND low.", Toast.LENGTH_SHORT);
            }

But it doesn't detect nothing was entered. Any ideas?

Thanks!

A: 

Maybe like this?

String value = editText.getText().toString();
if (value == "")
{
    // your code here
}
BennySkogberg
Not working either. :(
Allen Gingrich
+1  A: 

Please compare string value not with == but .equals :
String yourString = ; if (marketValHigh.getText().toString().equals("")) { // This should work! }

Sephy
As I said above: This works to stop progression to the next activity, but my toast does not show. Any ideas?Thanks!
Allen Gingrich
Whoops, my fault. Didn't add .show()!
Allen Gingrich
+1  A: 

This will check if ur edittext is empty:

if (marketValLow.getText().toString().trim().equals("")) { }

RockOn
This works to stop progression to the next activity, but my toast does not show. Any ideas?Thanks!
Allen Gingrich
Toast.makeText(CurrentMarketValue.this, "You need to enter a high AND low.", Toast.LENGTH_SHORT).show();This will work.
RockOn
A: 

rather what u can check is like String text = mSearchText.getText().toString();

if (text != null && text .trim().length() > 0) { // your code }

A: 

If it stops progression to the next activity but doesn't show the toast there must be something wrong in your else statement. Have you read the Dev Guide article on Toast notifications? It is under User Interface -> Notifying the User -> Creating Toast Notifications.

Zhehao Mao