HorizontalListView中setSelection方法没有实现的数据刷新的解决方法

前段时间在项目中用到了HorizontalListView的一些东东,后来在项目中数据刷新的时候需要回到第一项,想使用setSelection方法,却发现这个开源的代码没有实现这个方法。

1 @Override
2 public void setSelection(int position) {
3       
4 }

该如何解决呢?

后来通过查看源代码,发现数据刷新后,程序回到记录的上一个位置。

protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        if (mAdapter == null) {
            return;
        }

        if (mDataChanged) {
                    ...................................................
                }


.........................................

}

 

查看数据更新的源码:

if (mDataChanged) {
            // comment by lixin for reset x location(2013-03-21)
            // int oldCurrentX = mCurrentX;
            // modify by lixin 2012-04-02 因为有需求不改变位置
            int oldCurrentX = 0;
            if (!needResetLocate) {
                oldCurrentX = mCurrentX;
            }

            initView();
            removeAllViewsInLayout();
            // comment by lixin for reset x location(2013-03-21)
            // mNextX = oldCurrentX;
            // modify by lixin 2012-04-02 因为有需求不改变位置
            if (!needResetLocate) {
                mNextX = oldCurrentX;
            }
            mDataChanged = false;
        }

在代码中加入一个标志位用来对位置进行记录分支。

posted @ 2013-05-02 14:54  ItNoob  阅读(2021)  评论(1编辑  收藏  举报