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

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

转载于:https://www.cnblogs.com/ItNoob/archive/2013/05/02/HorizontalListView_set_selection.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值