Android – listview hides some items

I want to hide some items in the listview according to some standards. I found two solutions, but none of them is valid. I tried to return empty view from the getitem() method, but the divider is still visible. Therefore, if I hide all items, for example, it will lead to a large number of separation lines. The second is to set view.go in the getitem() method. But the listview still reserves position for invisible items, This leads to an empty view in my list. Has anyone found a solution to this problem?

Edit: in addition, I need to note that I cannot delete any data from the dataset. The adapter / listview must only hide the specified items

resolvent:

I will achieve this by:

>Create a list / array inside the adapter that will hold the index of the items to be hidden

For example:

List<Integer> hiddenItems;

>Rewrite the adapter getcount () method to return items in the list of numbers and reduce the number of items in the collection, as mentioned in step 1

For example:

@Override
public int getCount() {
    return items.size() - hiddenItems.size();
}

>The items that override getitem () to return the index offset are included in the collection in step 1

For example:

@Override
public Object getItem(int position)
{
    for (Integer hiddenIndex : hiddenItems) {
        if(hiddenIndex <= position)
            position++;
    }

    // Now your regular getItem code...
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>