谷歌+像 ViewPager 页面指示器

发布于 2025-01-08 13:55:18 字数 745 浏览 3 评论 0原文

我尝试自定义 页面指示器,但成功了一半,但几个小时后我被困住了,我不知道问题是什么。 所以我想更改固定日期名称的标题,从星期一到星期五,没有周末,起始位置是当天。 目前名称还可以,但是当我启动应用程序时,当前位置是星期五,下一个是星期六,当我滑动时,标题会变回正常,星期一到油炸。 所以问题就出在起始位置上。

这是标题的代码。

public String getTitle(int pos){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, 2);
        cal.add(Calendar.DAY_OF_WEEK, pos);
        return readableDateFormat.format(cal.getTime());
    }

对于我使用的职位。

static int day = calendar.get(Calendar.DAY_OF_WEEK); if(天==0 || 天==7) mViewPager.setCurrentItem(1); else mViewPager.setCurrentItem(day);

在我更改标题之前,定位效果很好。 因此,如果有人知道我做错了什么,请帮助。

im trying to customize this page indicator with half succes, but after many hours im stuck and i dont know whats the problem.
So i want to change the titles for fix day names, from monday to friday, without weekends, and the start position is the current day.
Currently the names are okay,but when i start the app, the current position is friday and the next is saturday, when i swipe, the titles change back to normal, mon to fry.
So the problem is the start position.

Here is the code for the titles.

public String getTitle(int pos){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, 2);
        cal.add(Calendar.DAY_OF_WEEK, pos);
        return readableDateFormat.format(cal.getTime());
    }

And for the position i used this.

static int day = calendar.get(Calendar.DAY_OF_WEEK);
if(day==0 || day==7)
mViewPager.setCurrentItem(1);
else mViewPager.setCurrentItem(day);

Before i changed the titles the positioning worked well.
So if anyone know what i did wrong please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2025-01-15 13:55:18

我刚刚发现问题,这是我的错,我以为星期一的数字是1。解决方案是:

if(day==7 || day==8){ mViewPager.setCurrentItem(0); mViewPager.setCurrentItem(day-2); } else { mViewPager.setCurrentItem(day-2); }

i just found the problem, it was my fault, i thought monday 's number is 1. the solution is:

if(day==7 || day==8){ mViewPager.setCurrentItem(0); } else { mViewPager.setCurrentItem(day-2); }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文