Android: как программно вызвать событие onScroll в ListView - PullRequest
5 голосов
/ 27 мая 2011

Я пытаюсь программно вызвать onScroll событие в ListView.

Кто-нибудь может мне помочь?

Вот мой код:

@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);
    }
}

1 Ответ

6 голосов
/ 27 мая 2011

Из официальной документации :

public void smoothScrollByOffset (int offset) 

или

public void smoothScrollToPosition (int position) 
...