Android SwiperefreshLayout指示器在设置刷新(false)后是否继续显示在viewpager内部?
我正在使用滑动刷新布局来刷新数据,但问题是,即使我在viewpager中设置了setRefreshing(false),刷新指示器仍会持续显示刷新 这是我的密码:Android SwiperefreshLayout指示器在设置刷新(false)后是否继续显示在viewpager内部?,android,android-viewpager,swiperefreshlayout,Android,Android Viewpager,Swiperefreshlayout,我正在使用滑动刷新布局来刷新数据,但问题是,即使我在viewpager中设置了setRefreshing(false),刷新指示器仍会持续显示刷新 这是我的密码: private static class DayPagerAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener, SwipeRefreshLayout.OnRefreshListener { pri
private static class DayPagerAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener,
SwipeRefreshLayout.OnRefreshListener
{
private Context context;
private boolean isDragging;
private final ActionsState actionsState;
private int currentPageIndex;
private ListView listView;
private boolean isWeekChanging;
public ActionsListAdapter listAdapter;
private SwipeRefreshLayout swipeRefreshLayout;
private final List<String> DAYS_LIST = ImmutableList.of(
"SUN",
"MON",
"TUE",
"WED",
"THU",
"FRI",
"SAT"
);
public DayPagerAdapter(Context context, ActionsState actionsState)
{
this.context = context;
this.actionsState = actionsState;
listAdapter = new ActionsListAdapter(actionsState);
//save the current page index to determine the left and right swipe
currentPageIndex = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1;
}
@Override
public Object instantiateItem(ViewGroup container, int position)
{
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.actions_days_pager_item, container, false);
listView = (ListView) layout.findViewById(R.id.actions_list_view);
swipeRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.actions_swipe_refresh_container);
swipeRefreshLayout.setOnRefreshListener(this);
listAdapter.bindToView(listView);
if (Throttle.REFRESH_CUSTOMER_TASKS_ON_ACTIONS_OPEN.shouldRun())
{
refreshCustomerTasksForCurrentDate();
}
container.addView(layout);
return layout;
}
@Override
public int getCount()
{
return DAYS_LIST.size();
}
@Override
public CharSequence getPageTitle(int position)
{
return DAYS_LIST.get(position);
}
@Override
public boolean isViewFromObject(View view, Object object)
{
return object == view;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
int nextPosition = position + 1;
if (isDragging)
{
if (positionOffset > 0.0001 && nextPosition < getCount())
{
isWeekChanging = false;
}
else
{
isWeekChanging = true;
}
}
}
@Override
public void onPageSelected(int position)
{
actionsState.invalidateOptionMenu();
if (isWeekChanging)
{
isWeekChanging = false;
listAdapter.recalculateListItems();
}
else if (position > getCurrentPageIndex())
{
if (listView != null)
{
actionsState.setLocalDate(actionsState.getLocalDate().plusDays(position - getCurrentPageIndex()));
listAdapter.recalculateListItems();
}
}
else if (getCurrentPageIndex() > position)
{
if (listView != null)
{
actionsState.setLocalDate(actionsState.getLocalDate().minusDays(getCurrentPageIndex() - position));
listAdapter.recalculateListItems();
}
}
currentPageIndex = position;
}
public final int getCurrentPageIndex()
{
return currentPageIndex;
}
@Override
public void onPageScrollStateChanged(int state)
{
if (isDragging && getCurrentPageIndex() == 0 && isWeekChanging)
{
isDragging = false;
actionsState.setLocalDate(actionsState.getLocalDate().minusDays(1));
actionsState.setCurrentItem(6);
}
else if (isDragging && getCurrentPageIndex() == 6 && isWeekChanging)
{
isDragging = false;
actionsState.setLocalDate(actionsState.getLocalDate().plusDays(1));
actionsState.setCurrentItem(0);
}
// actionsState.getSwipeRefreshLayout().setEnabled(state == ViewPager.SCROLL_STATE_IDLE);
isDragging = state == ViewPager.SCROLL_STATE_DRAGGING;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View) object);
}
public void stopWeekChanging()
{
this.isWeekChanging = true;
}
public void scrollToFirstBooleanTask()
{
listView.setSelection(listAdapter.getPositionOfFirstBooleanTask());
}
@Subscribe
public void onFoodLogUpdated(FoodLogUpdatedEvent event)
{
if (event.getDateRange().includesDate(actionsState.getLocalDate()))
{
if (listAdapter != null)
{
// this is weaker than recalculateListItems, and is used because an update to the food log can't add/remove items
notifyDataSetChanged();
}
}
}
@Subscribe
public void onFitbitLinkChanged(FitbitLinkChangedEvent event)
{
if (listAdapter != null)
{
listAdapter.recalculateListItems();
}
}
@Subscribe
public void onIHealthAuthUpdated(IHealthAuthUpdatedEvent event)
{
if (listAdapter != null)
{
listAdapter.recalculateListItems();
}
}
@Subscribe
public void onScheduledCallsChanged(ScheduledCallsChangedEvent event)
{
if (listAdapter != null)
{
listAdapter.recalculateListItems();
}
}
@Subscribe
public void onCustomerTaskUpdated(CustomerTaskUpdatedEvent event)
{
if (swipeRefreshLayout != null)
{
swipeRefreshLayout.setRefreshing(false);
}
if (event.getDateRange().includesDate(actionsState.getLocalDate()))
{
if (listAdapter != null)
{
listAdapter.recalculateListItems();
}
}
}
@Override
public void onRefresh()
{
refreshCustomerTasksForCurrentDate();
}
private void refreshCustomerTasksForCurrentDate()
{
swipeRefreshLayout.setRefreshing(true);
Vida.getCustomerTaskManager().forceRefreshCustomerTasksForDate(actionsState.getLocalDate());
}
}
私有静态类DayPagerAdapter扩展PagerAdapter实现ViewPager.OnPageChangeListener,
SwipeRefreshLayout.OnRefreshListener
{
私人语境;
私密的布林拉格;
私人最终诉讼状态诉讼状态;
私有int-currentPageIndex;
私有列表视图列表视图;
私有布尔值是一个很小的变化;
公共行动列表适配器;
私人SwipeRefreshLayout SwipeRefreshLayout;
私人最终列表天数\u List=ImmutableList.of(
“太阳”,
“周一”,
“星期二”,
“WED”,
“THU”,
“星期五”,
“SAT”
);
public DayPagerAdapter(上下文、操作状态、操作状态)
{
this.context=上下文;
this.actionsState=actionsState;
listAdapter=newactionsListAdapter(actionsState);
//保存当前页面索引以确定向左和向右滑动
currentPageIndex=Calendar.getInstance().get(Calendar.DAY\u OF_WEEK)-1;
}
@凌驾
公共对象实例化项(视图组容器,int位置)
{
LayoutFlater充气机=LayoutFlater.from(上下文);
视图布局=充气机。充气(R.layout.actions\u days\u pager\u item,container,false);
listView=(listView)layout.findViewById(R.id.actions\u list\u view);
swipeRefreshLayout=(swipeRefreshLayout)layout.findViewById(R.id.actions\u swipe\u refresh\u container);
swipeRefreshLayout.setOnRefreshListener(此);
bindToView(listView);
if(Throttle.REFRESH\u CUSTOMER\u TASKS\u ON\u ACTIONS\u OPEN.shouldRun())
{
RefreshCustomerTaskForCurrentDate();
}
container.addView(布局);
返回布局;
}
@凌驾
public int getCount()
{
返回天数_LIST.size();
}
@凌驾
公共字符序列getPageTitle(int位置)
{
返回天数列表。获取(位置);
}
@凌驾
公共布尔值isViewFromObject(视图,对象)
{
返回对象==视图;
}
@凌驾
已滚动页面上的公共无效(int-position、float-positionOffset、int-positionOffsetPixels)
{
int nextPosition=位置+1;
if(ISDRAGING)
{
如果(位置偏移>0.0001&&nextPositiongetCurrentPageIndex())
{
如果(listView!=null)
{
actionsState.setLocalDate(actionsState.getLocalDate().plusDays(position-getCurrentPageIndex());
listAdapter.RecomcalElistitEMS();
}
}
else if(getCurrentPageIndex()>位置)
{
如果(listView!=null)
{
actionsState.setLocalDate(actionsState.getLocalDate().minusDays(getCurrentPageIndex()-position));
listAdapter.RecomcalElistitEMS();
}
}
currentPageIndex=位置;
}
公共最终整型getCurrentPageIndex()
{
返回当前页面索引;
}
@凌驾
公共无效onPageScrollStateChanged(int状态)
{
if(IsDraging&&getCurrentPageIndex()==0&&IsWeekChange)
{
IsDraging=错误;
actionsState.setLocalDate(actionsState.getLocalDate().minusDays(1));
动作状态设置当前项(6);
}
else if(IsDraging&&getCurrentPageIndex()==6&&IsWeekChange)
{
IsDraging=错误;
actionsState.setLocalDate(actionsState.getLocalDate().plusDays(1));
actionsState.setCurrentItem(0);
}
//actionsState.getSwipeRefreshLayout().setEnabled(状态==ViewPager.SCROLL\u状态\u空闲);
IsDraging=state==ViewPager.SCROLL\u state\u拖动;
}
@凌驾
公共项(视图组容器、int位置、对象)
{
container.removeView((视图)对象);
}
公共无效StopWeekChang()
{
this.isweekchangg=true;
}
public void scrollToFirstBooleanTask()的滚动条
{
setSelection(listAdapter.getPositionOfFirstBooleanTask());
}
@订阅
公共void onFoodLogUpdated(FoodLogUpdateEvent事件)
{
if(event.getDateRange().includeDate(actionsState.getLocalDate()))
{
if(listAdapter!=null)
{
//这比重新计算的条目弱,之所以使用它是因为食品日志的更新无法添加/删除条目
notifyDataSetChanged();
}
}
}
@订阅
公共无效onFitbitLinkChanged(FitbitLinkChangedEvent事件)
{
if(listAdapter!=null)
{
listAdapter.RecomcalElistitEMS();
}
}
@订阅
公共无效OnHealthAuthUpdated(iHealthAuthUpdateEvent事件)
{
if(listAdapter!=null)
{
listAdapter.RecomcalElistitEMS();
}
}
@订阅
在ScheduledCallSchanged上的公共无效(ScheduledCallsChangedEvent事件)
{
if(listAdapter!=null)
{
listAdapter.RecomcalElistitEMS();
}
}
@订阅
公共空间
private void refreshCustomerTasksForCurrentDate()
{
swipeRefreshLayout.setRefreshing(true);
Vida.getCustomerTaskManager().forceRefreshCustomerTasksForDate(actionsState.getLocalDate());
//todo: swipeRefreshLayout.setRefreshing(false); after data load
}