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 内容?
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
