停止滚动的列表视图 [英] Stop scrolling in a listview

查看:197
本文介绍了停止滚动的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在活动列表视图和ImageButton的。 当我点击我要到列表中的一个特定位置的ImageButton(我这样做致电:setSelection(INT位)就行了。 当用户甩列表视图,然后单击ImageButton的出现问题。 这样的例子不胜枚举到指定的位置,但继续滚动。

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 position) on the list. The problem occurs when the user flings the listview and then clicks the imagebutton. The list goes to the specified position but continues scrolling.

如。当我进入一扔模式下,单击该按钮,然后我去了第四名的位置,但在ListView不断滚动,所以我最终选择了25

eg. when I go into fling mode, click the button, then I go to the fourth position, but the listview keeps scrolling, so I end up with a selection of 25

推荐答案

我有写简单的方法使用反射来停止scoll的ListView。

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) {}
}

只需拨打stopScroll(myListView);当你需要停止滚动。

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

这篇关于停止滚动的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆