0

I have custom gridview adapter in the getview method I am checking String for NULL or Empty, but the condition does not seem to work as it prints string "null" to the textview below is the code

if(!ThisAttendee.AllocatedTable.equals(null) && ThisAttendee.AllocatedTable.toLowerCase().trim() != "null" && !ThisAttendee.AllocatedTable.trim().isEmpty())
        {
            ((TextView)(gridviewitem.findViewById(R.id.tv_attendeetable))).setText("Table: "+ThisAttendee.AllocatedTable);
        }
Syed Waqas
  • 862
  • 2
  • 9
  • 29

1 Answers1

1

You need to use .equals() instead of == to check if the String is "null", and == instead of equals() to check for null.

See https://stackoverflow.com/a/767379/675383

Community
  • 1
  • 1
nhaarman
  • 98,571
  • 55
  • 246
  • 278
  • I have changed it to `if(ThisAttendee.AllocatedTable != null && !ThisAttendee.AllocatedTable.toLowerCase().trim().equals("null") && !ThisAttendee.AllocatedTable.trim().equals("")) { ((TextView)(gridviewitem.findViewById(R.id.tv_attendeetable))).setText("Table: "+ThisAttendee.AllocatedTable); }` now it prints text table only I tried what you suggested above but same result – Syed Waqas Jun 09 '13 at 13:04
  • actually the text table was coming from the xml where I was hardcoding textview to text to be visible in the design mode ;) – Syed Waqas Jun 09 '13 at 13:10