Rookie Rookie - 4 months ago 14
Android Question

Skip a row in list view

I guess

getView()
is called for each item of the list, but my question is, Can we not show the row if data associated with that row is null. I want to do this inside
getView ()
only.

For Example:

If the alerts for a person whose name is to be shown in list view are null.I don't want to display that person's name in list view.

Tim Tim
Answer

You can set the visibility of that row to "gone" in the last line before returning the View - that should work for you.

Edit: Be sure to set visibility to visible if the content is not null - otherwise all the views will become "gone" as the ListView reuses views.

myView.setVisibility((myData == null) ? View.GONE : View.VISIBLE);