android - Swiperefresh listview, updates but not how you would expect -
i have listview using swipefresh feature, , i've encountered weird problem. when swipe down, see animation , information (updates behind scenes.) however, can't see updated information, until physically scroll down , again. moment scroll towards top old data replaced new data.
swipe// swipelayout = (swiperefreshlayout) findviewbyid(r.id.swipe_container); swipelayout.setcolorschemeresources(android.r.color.holo_blue_light, android.r.color.holo_green_light); final textview rndnum = (textview) findviewbyid(r.id.timestamp); swipelayout.setonrefreshlistener(new swiperefreshlayout.onrefreshlistener() { @override public void onrefresh() { log.i("refreshing", " onrefresh called swiperefreshlayout"); initiaterefresh(); } }); asynctask// private void initiaterefresh() { log.i("irefreshing", "initiaterefresh"); /** * execute background task, uses {@link android.os.asynctask} load data. */ new bgrefresh().execute(); } private class bgrefresh extends asynctask<void, void, boolean> { static final int task_duration = 3 * 1000; // 3 seconds @override protected boolean doinbackground(void... params) { // sleep small amount of time simulate background-task try { thread.sleep(task_duration); } catch (interruptedexception e) { e.printstacktrace(); } arraylist<string> blah = new arraylist<>(); try { // simulate network access calendar cal = calendar.getinstance(); simpledateformat month_date = new simpledateformat("m"); string monthname = month_date.format(cal.gettime()); int lastdayofmonth =(cal.getactualmaximum(calendar.day_of_month)); int currentyear = calendar.getinstance().get(calendar.year); int year = calendar.getinstance().get(calendar.year); ; calendar.getinstance().getactualmaximum(calendar.day_of_month); cal.set(calendar.day_of_month,1); monthname = month_date.format(cal.gettime()); //string test = cal.gettime(); //start_date_monthly_statements=5/1/15&end_date_monthly_statements=5/27/15&activity_detail_type=all®_captcha=&display= string startdaterecentactivity = monthname + "/1/" + currentyear; string enddaterecentyactivity = monthname + "/" + lastdayofmonth + "/" + currentyear; ///second calendar calendar cal2 = calendar.getinstance(); cal2 = calendar.getinstance(); // cal.add(calendar.day_of_month, -5); //go previous month webcreate web = new webcreate(); try { //clear , go. fields.clear(); values.clear(); fields.add("data1"); values.add(datav1"); cal = calendar.getinstance(); month_date = new simpledateformat("mm-dd-yyyy hh:mma"); string date = month_date.format(cal.gettime()); date = date.replace("-", "/"); date = date.replace(" ", "\n"); refreshts = (textview) findviewbyid(r.id.timestamp); refreshts.settext(date); mmainlistadapter = new customlistviewadapter(getapplicationcontext(), fields, values); madapter.n } catch (exception e) { e.printstacktrace(); return false; } thread.sleep(2000); } catch (interruptedexception e) { return false; } } @override protected void onpostexecute(boolean result) { super.onpostexecute(result); madapter.notifydatasetchanged(); // tell fragment refresh has completed onrefreshcomplete(result); } } private void onrefreshcomplete(boolean result) { log.i("log_tag", "onrefreshcomplete"); // remove items listadapter, , replace them new items //mlistadapter.clear(); //for (string cheese : result) { // mlistadapter.add(cheese); //} // stop refreshing indicator swipelayout.setrefreshing(false); }
what or cause this?
looks view of code have 2 adapters? mmainlistadapter , madapter? since data appears when scroll back, means aren't notifying adapter have updated data. call notifydatasetchanged() on other adapter, since mmainlistadapter appears main adapter.
Comments
Post a Comment