android - How to refer to data in a previous viewpager -
i have android project using fragments , viewpager. using separate countdown timer every page, runs when view of page 'onscreen'. @ first time every page same, after while page 1 might 20 seconds left, page 2 60 seconds , on.
my problem don't know how save remaining time, moment user swipes next page. using onpagestatelistener has next code, saving new value of questionid , old value of new time. how refer value of questionid , matching newtime-value of page in view before user swiped?
viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { public void onpagescrollstatechanged(int state) { if (state == viewpager.scroll_state_dragging) { savetime(); } } public void onpagescrolled(int position, float arg1, int arg2) {} public void onpageselected(int pos) { questionid = mquestions.get(pos).getnr() runtime(); } }); public void savetime(){ mquestions.get(questionid).settime(newtime); } public void runtime(){ if (mtimer != null) { mtimer.cancel(); mtimer = null; } mtimer = new countdowntimer(90000, 1000) {//millisinfuture, countdowninterval public void ontick(long millisuntilfinished) { newtime = (millisuntilfinished/1000); } public void onfinish() { } }.start(); }
first of can utilize sharedpreferences
.
besides, of course of study can save info in adapter utilize viewpager, can save info in db or create singleinstance in parent activity or fragment.
android android-fragments android-viewpager
No comments:
Post a Comment