Unexpected response when capturing text from a TextView

2

I have to test a certain TextView to see if it is populated in the onCreate () of the activity and if it is populated, I have to swap the image of an ImageButton. I'm using the following code for this:

if (txt_photo_path.getText().toString() != null) {
        btnenviarfoto.setImageResource(R.drawable.enviarfotochecked);
        }

However, the code is always running. I've decided to test to see why the TextView is always filled, using the following, inside the if:

Log.w("txt_photo_path", txt_photo_path.getText().toString()); 

What I get in my log is below

09-05 12:56:53.161  14726-14726/com.ufscar.ufscar.df100fogo W/txt_photo_path﹕ [ 09-05 12:56:53.381   576:  591 I/ActivityManager ]

Why is this happening? How to tell if TextView is really empty or not?

    
asked by anonymous 05.09.2014 / 18:06

1 answer

1

Apparently the TextView is always filled with an empty string (""). Just changing

if (txt_photo_path.getText().toString() != null)

by

if (!txt_photo_path.getText().toString().isEmpty())

That worked perfectly.

    
05.09.2014 / 18:30