如何更新 ViewPager 内容? [英] How to update ViewPager content?

查看:12
本文介绍了如何更新 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 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆