@Override public void onRefresh(final Object param) { final LVRefreshListView view = getView(); if (view != null && LuaUtil.isValid(mCallback)) { // 这里必须放在handler中执行,否则会造成nullpointerexception(dispatchDraw的时候调用removeView出错) // http://dashasalo.com/2013/09/16/android-removeview-crashes-animation-listener/ view.post( new Runnable() { // 下一帧回调,否则会造成view onDraw乱序。否则在同一帧调用的时候再调用addView, removeView会有bug @Override public void run() { if (LuaUtil.isValid(mCallback)) { LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "PullDown", "pullDown")); } if (param instanceof OnLVRefreshListener) { ((OnLVRefreshListener) param).onRefresh(null); } } }); } else { if (param instanceof OnLVRefreshListener) { ((OnLVRefreshListener) param).onRefresh(null); } } }
/** * 停止刷新 * * @return */ public UDRefreshListView stopPullDownRefreshing() { final LVRefreshListView lv = getView(); if (lv != null) { lv.stopPullDownRefreshing(); } return this; }
/** * 设置是否可以刷新 * * @param enable */ public UDRefreshListView setRefreshEnable(boolean enable) { final LVRefreshListView view = getView(); if (view != null) { view.setEnabled(enable); if (!enable) { view.setOnRefreshListener(null); } } return this; }
/** 初始化下拉刷新 */ public void initPullRefresh() { final LVRefreshListView view = getView(); if (view != null && LuaUtil.isValid(mCallback)) { view.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { UDRefreshListView.this.onRefresh(null); } }); } }