views:

40

answers:

1

My application uses a list of media files on the phone, i.e. images, audio and video. It also allows the user to filter the list via some checkboxes in a menu, so the user can choose to show or hide each type of files.

The way I've been doing this is by putting this in the adapter's getView():

        // don't show unwanted file types
        if (cmo.hasType(MediaType.AUDIO_FILE)){
            if(!prefs.getBoolean(PREFS_SHOWAUDIO, true)){
                return new ViewStub(mContext);;
            }
        }else if(cmo.hasType(MediaType.IMAGE_FILE)){
            if(!prefs.getBoolean(PREFS_SHOWIMG, true)){
                return new ViewStub(mContext);;
            }

        }else if( cmo.hasType(MediaType.VIDEO_FILE)){
            if(!prefs.getBoolean(PREFS_SHOWVIDEO, true)){
                return new ViewStub(mContext);;
            }
        }

which is quite effective in the sense that the list doesn't show those elements. However, the ListView still renders a 1px grey line between each View, even if they are ViewStubs, meaning I see a thick grey line whenever a group of consecutive items are filtered away.

How can I get rid of those lines? Should I create a new data array, containing only the elements that should show a view?

A: 

I think Adapter isn't a good place to add list logic. It's for fetching and displaying data, not for making decisions, what to show/hide. As you can see there is no way to not add a View for given index (in getView() method).

You should filter your list before you will pass it to an Adapter.

Brutall
That makes sense. I was put off by the idea of having two data arrays in the adapter (one with all the data, one with only the ones I want to show) - however I guess there's no reason to have the one with all the data - which is essentially a cache, in the adapter. The cache and filter logic should be outside, and the adapter should just display its content, which comes pre-filtered, in a straightforward manner.
OhHiThere