gpt4 book ai didi

android - 不要在 ViewPager 中使用 PageListener

转载 作者:行者123 更新时间:2023-11-29 00:13:42 25 4
gpt4 key购买 nike

我想为 ViewPager 设置 PageListener,但我的代码不起作用。

这是我的代码

监听类:

private class PageListener extends ViewPager.SimpleOnPageChangeListener {
public void onPageSelected(int position) {
currentPage = position;
if (currentPage == 0) {
((DashboardActivity) getActivity()).hideArcMenu();
} else if (currentPage == 1) {
((DashboardActivity) getActivity()).hideArcMenu();
} else if (currentPage == 2) {
if (DatabaseManager.getInstance(getActivity()).getAllHistoryCardsCountById(((DashboardActivity) getActivity()).getCarId()) <= 0) {
((DashboardActivity) getActivity()).showArcMenu();
}
}
}
}

并设置为ViewPager:

vpPager.setOnPageChangeListener(new PageListener());

最佳答案

试试这段代码:

vpPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position)
{
currentPage = position;
if (currentPage == 0) {
((DashboardActivity) getActivity()).hideArcMenu();
} else if (currentPage == 1) {
((DashboardActivity) getActivity()).hideArcMenu();
} else if (currentPage == 2) {
if (DatabaseManager.getInstance(getActivity()).getAllHistoryCardsCountById(((DashboardActivity) getActivity()).getCarId()) <= 0) {
((DashboardActivity) getActivity()).showArcMenu();
}
}
}
@Override
public void onPageScrollStateChanged(int state)
{
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
}
});

关于android - 不要在 ViewPager 中使用 PageListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28190426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com