开发者

Android, Adapter: Filtering via getView() still leaves gray lines

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(开发者_JAVA百科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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜