Android / SQL Server: Set Text to "No time" if the data at database is NULL

52 Views Asked by At

at my database table, there's a column name "time_photo_before". The column automatically set to NULL if there's no data.

At android, I got a problem. Although I set the text to "No time" when the data is null, but it still appears the next "null" at the TextView. But if there's a data, the data will display. Below is my code:

    timePhotoBefore = findViewById(R.id.timePhotoBefore);

    if(taskClass.getTime_photo_before() != null ){
        timePhotoBefore.setText(taskClass.getTime_photo_before());

    }else {
        timePhotoBefore.setText("No time");
    }

Can I know what is the problem?

1

There are 1 best solutions below

0
Htin Linn Zaw On BEST ANSWER

I think you should write like this!

timePhotoBefore = findViewById(R.id.timePhotoBefore);

    if(taskClass.getTime_photo_before() != null )
    {
        timePhotoBefore.setText(taskClass.getTime_photo_before());
        if (timePhotoBefore.getText().equals("NULL")
            timePhotoBefore.setText("No Time");
    }
    else
    {
        timePhotoBefore.setText("No time");
    }