Android:如何在 ListView 中以编程方式调用 onScroll 事件

标签 android events onscroll

我正在尝试以编程方式调用 ListView 中的 onScroll 事件。

谁能帮帮我?

这是我的代码:

@RunWith(RobolectricTestRunner.class)
public class ActivityListViewTest {

    private ActivityListView activity;

    @Before
    public void setUp() throws Exception {
        activity = new ActivityListView();
    }

    @Test
    public void shouldUpdateListViewChildCountOnCreate() throws Exception{
        activity.onCreate(null);
        ListView calendarListView = (ListView)activity.findViewById(R.id.listview);

        assertTrue("CHILD COUNT IS: " + calendarListView.getChildCount(), calendarListView.getChildCount() > 0);

        // Here i want to invoke onScroll event. Then ListView must update and listView items count become to be more that 20

        assertTrue("CHILD COUNT IS: " + calendarListView.getChildCount(), calendarListView.getChildCount() > 20);
    }
}

最佳答案

来自official documentation :

public void smoothScrollByOffset (int offset) 

public void smoothScrollToPosition (int position) 

关于Android:如何在 ListView 中以编程方式调用 onScroll 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152322/

相关文章:

objective-c - NSTextField 没有诸如 'Editing did Change' 之类的事件?

javascript Window.onscroll 垂直移动 div

javascript - 工具栏隐藏在 listView 中向上滚动但向下滚动时不会返回

java - 组织.json.JSONException : End of input at character 0 of while creating a JSON Object

Javascript - 检查是 Web App 还是 Android App

c++ - 在 C++ 中,有没有办法让 Child 重用 GrandParent 中定义的纯虚函数的 Parent 类实现

javascript - 滚动事件不起作用

android - 我可以在中国使用 Google Maps API吗

java - 未找到 AdView 类

javascript - 将值传递给 .bind() 方法