如何更新ViewPager内容?内容、ViewPager

2023-09-04 23:27:36 作者:搜索中...

我有这个 PageAdapter 为期一周的日子里,每一个寻呼机我有同样的布局。我的问题是,当改变的日子如何更新正确的ListView。当我的日子改变传呼机创建一个新的寻呼机和删除等,这种情况发生时我的列表视图指向新的寻呼机,但不是当前。例如,在wedneyday我保存列表视图的参考,当我更改周二周一寻呼机是创建和星期四被删除,而我的参考点,以最后一页创建(星期一),但我在星期二。

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.

我的pageAdapter:

My pageAdapter:

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 总是指向当前项目的列表视图。

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.

 
精彩推荐