简体   繁体   English

Android:ListView,最小滚动位置

[英]Android: ListView, min scroll position

I have 10 items in ListView. 我在ListView中有10个项目。 Sometimes I dont want user to be able to see first list item. 有时我不希望用户能够看到第一个列表项。 So Second one should be like first one. 所以第二个应该像第一个一样。

How to prevent user to scroll to the first item ? 如何防止用户滚动到第一项? Or maybe there is better solutions or ready API to do that ? 或者,也许有更好的解决方案或现成的API可以做到这一点?

PS: HeaderView not works for me PS:HeaderView不适合我

The best solution would be to simply remove (temporarily) the item from your List (or whichever collection you are using), and then re-fill the ListView with: 最好的解决方案是简单地(暂时)从列表(或您使用的任何集合)中删除该项目,然后用以下方法重新填充ListView:

listView.notifyDataSetChanged();

Another thing you could do is return an empty view when your 'position == 0' so the first item would not be displayed you'd also have to call the 'notifyDataSetChanged()' method here when the condition would change. 您可以做的另一件事是,当'position == 0'时返回一个空视图,这样就不会显示第一项,当条件发生变化时,您还必须在此处调用'notifyDataSetChanged()'方法。

This code will block the first item from being seen by selecting the second item on the list. 通过选择列表中的第二项,此代码将阻止显示第一项。

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
            if (i == 0)
                absListView.setSelection(1);
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM