[英]setting default swiping tab based on time/date in android
我在Android的一項活動中有十個滑動標簽,我將它們從標簽1命名為標簽10。我想每天設置默認標簽
例如,假設我的標簽4是2015年11月15日 ,那么我想將標簽4設置為該天的默認標簽,然后將默認標簽更改為第二天的 標簽5 。
任何可能的解決方案..請分享..謝謝
如果您使用的是ViewPager
則就像在ViewPager
調用setCurrentItem(int item)
或setCurrentItem(int item, boolean smoothScroll)
ViewPager
public void setCurrentItem(int項目)
設置當前選擇的頁面。 如果ViewPager已經使用其當前適配器通過其第一個布局,則在當前項目和指定項目之間將有平滑的動畫過渡。
參量
item-要選擇的項目索引
public void setCurrentItem(int item,boolean smoothScroll)
設置當前選擇的頁面。
參量
item-要選擇的項目索引
smoothScroll-為true可以平滑滾動到新項目,為false可以立即過渡
完成。 我只是用這種方式。
try {
String day1 = "12-Nov-2015 12:04 PM";
SimpleDateFormat formater1 = new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
Date date1 = formater1.parse(day1); // You will need try/catch around this
long millis1 = date1.getTime();
String day2 = "12-Nov-2015 12:05 PM";
SimpleDateFormat formater2 = new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
Date date2 = formater2.parse(day2); // You will need try/catch around this
long millis2 = date2.getTime();
if((currentTime>=millis1) &&(currentTime<millis2)) {
Toast.makeText(this,"in 1st",Toast.LENGTH_SHORT).show();
viewPager.setCurrentItem(5, false);
}
if(currentTime>=millis2) {
Toast.makeText(this,"in 2nd",Toast.LENGTH_SHORT).show();
viewPager.setCurrentItem(7, false);
}
} catch (ParseException e) {
//Handle exception here, most of the time you will just log it.
e.printStackTrace();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.