Stop scrolling in a listview

后端 未结 6 2393
挽巷
挽巷 2021-02-15 16:32

I have in my activity a listview and an imagebutton. When I click the imagebutton I want to go to a specific position in the list (I do this by calling: setSelection(int positio

6条回答
  •  死守一世寂寞
    2021-02-15 17:19

    I have write simple method to stop scoll ListView using reflection.

    private void stopScroll(AbsListView view)
    {
        try
        {
            Field field = android.widget.AbsListView.class.getDeclaredField("mFlingRunnable");
            field.setAccessible(true);
            Object flingRunnable = field.get(view);
            if (flingRunnable != null)
            {
                Method method = Class.forName("android.widget.AbsListView$FlingRunnable").getDeclaredMethod("endFling");
                method.setAccessible(true);
                method.invoke(flingRunnable);
            }
        }
        catch (Exception e) {}
    }
    

    Just call stopScroll(myListView); when you need to stop scroll.

提交回复
热议问题