How to update ViewPager content?(如何更新 ViewPager 内容?)
问题描述
我有这个 PageAdapter 一周中的几天,对于每个寻呼机我都有相同的布局.我的问题是如何在更改日期时更新正确的 listView.当我更改寻呼机创建新寻呼机并删除其他寻呼机的日期时,发生这种情况时,我的 listview 指向新寻呼机而不是当前寻呼机.例如,是星期三,我保存 listview 引用,当我更改为星期二时,创建星期一寻呼机并删除星期四,并且我的引用指向最后一页创建(星期一),但我在星期二.
i have this PageAdapter with days of the week, for each pager I have the same Layout. My problem is how update the right listView when change the day. When I change the day the Pager create a new pager and delete other, when this happened my listview point to new pager but not the current. For Example, is wedneyday and I save listview reference, when i change for Tuesday the monday pager is create and Thursday is deleted, and my reference point to last page create(monday) but I'm on tuesday.
我的页面适配器:
ListView lvwConfig;
@Override
public Object instantiateItem(View pager, int position) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.pager_layout, null);
lvwConfig = (ListView) v.findViewById(R.id.lvwConfig);
((ViewPager) pager).addView(v, 0);
return v;
}
我想让ListView总是指向当前项的listview.
I want to the ListView always point to listview of the current item.
推荐答案
阅读这篇文章:PagerAdapter
你可以在PagerAdapter中实现这个功能:
You can implement this function in PagerAdapter:
public int getItemPosition(Object object){
return POSITION_NONE;
}
之后,就可以使用这个功能了:
after, you can used this function:
yourPagerAdapterObject.notifyDataSetChanged();
如果要显示的视图过多,则此方法很糟糕.总是重新计算所有视图.但在你的情况下,对于某些观点,没关系.
This method is bad if you have too many views as to display. All the views are always recalculated. But in your case, for some views, it's okay.
这篇关于如何更新 ViewPager 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更新 ViewPager 内容?
基础教程推荐
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
