android–ListView OnScrollListener不会在ViewPager中调用

android–ListView OnScrollListener不会在ViewPager中调用,第1张

概述我有一个FragmentPagerAdapter,它创建它的子页面(ListFragments),如下所示:@OverridepublicFragmentgetItem(intposition){returnFragmentChildPage.newInstance();}我给ViewPager一个OffscreenPageLimit1.子ListFragments有一个自定义ScrollListener.我遇到的问

我有一个FragmentPagerAdapter,它创建它的子页面(ListFragments),如下所示:

@OverrIDepublic Fragment getItem(int position) {    return FragmentChildPage.newInstance();}

我给VIEwPager一个OffscreenPagelimit 1.子ListFragments有一个自定义ScrollListener.

我遇到的问题是自定义滚动侦听器仅适用于在VIEwPager滑过其OffscreenPagelimit时创建的子ListFragments,即子页面> 2.

更令人困惑的是,如果我滚动几个页面然后返回到第一页,则滚动侦听器现在可以工作.

这里发生了什么?似乎VIEwPager干扰了一些子页面OnScrollListener.

谢谢

解决方法:

试试吧.适合我!

public class ActivityTest extends SherlockFragmentActivity {    private VIEwPager mVIEwPager;    private TestAdapter mAdapter;    @OverrIDe    protected voID onCreate(Bundle arg0) {        super.onCreate(arg0);        mVIEwPager = new VIEwPager(this);        mVIEwPager.setID(androID.R.ID.button1);        setContentVIEw(mVIEwPager);        mAdapter = new TestAdapter(getSupportFragmentManager());        mVIEwPager.setAdapter(mAdapter);    }    private class TestAdapter extends FragmentPagerAdapter {        public TestAdapter(FragmentManager fm) {            super(fm);        }        @OverrIDe        public Fragment getItem(int position) {            return TestListFragment.newInstance(position);        }        @OverrIDe        public int getCount() {            return 10;        }    }    private static class TestListFragment extends SherlockListFragment {        private static final String TAG = TestListFragment.class.getSimplename();        private String[] mItems = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };        private int mPos;        @Suppresslint("ValIDFragment")        public static TestListFragment newInstance(int pos) {            TestListFragment frag = new TestListFragment();            Bundle b = new Bundle();            b.putInt("pos", pos);            frag.setArguments(b);            return frag;        }        @OverrIDe        public voID onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            mPos = getArguments().getInt("pos");        }        @OverrIDe        public voID onVIEwCreated(VIEw vIEw, Bundle savedInstanceState) {            super.onVIEwCreated(vIEw, savedInstanceState);            setlistadapter(new ArrayAdapter<String>(getSherlockActivity(), androID.R.layout.simple_List_item_1, mItems));            getListVIEw().setonScrollListener(new OnScrollListener() {                              @OverrIDe                public voID onScrollStateChanged(AbsListVIEw vIEw, int scrollState) {                }                @OverrIDe                public voID onScroll(AbsListVIEw vIEw, int firstVisibleItem, int visibleItemCount, int totalitemCount) {                    Log.d(TAG, "onScroll() - Fragment: " + mPos);                }            });        }    }}
总结

以上是内存溢出为你收集整理的android – ListView OnScrollListener不会在ViewPager中调用全部内容,希望文章能够帮你解决android – ListView OnScrollListener不会在ViewPager中调用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106423.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存