谷歌+像 ViewPager 页面指示器
我尝试自定义 此 页面指示器,但成功了一半,但几个小时后我被困住了,我不知道问题是什么。 所以我想更改固定日期名称的标题,从星期一到星期五,没有周末,起始位置是当天。 目前名称还可以,但是当我启动应用程序时,当前位置是星期五,下一个是星期六,当我滑动时,标题会变回正常,星期一到油炸。 所以问题就出在起始位置上。
这是标题的代码。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现问题,这是我的错,我以为星期一的数字是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); }