动态更改ViewPagerIndicator冠军 [英] Dynamically change ViewPagerIndicator titles

查看:194
本文介绍了动态更改ViewPagerIndicator冠军的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的项目使用了 ListFragments 来显示数据行。 该行得到动态更新的每几秒钟。行的数量随着每次更新和变化中的每一个 ListFragment

我想展现的行给用户的信息量,并认为这对于一个完美的地方是旁边的片段的在 ViewPagerIndicator 的。我提供了一个示例图像更好地融为一体prehension:

可悲的是我是pretty的无能如何实现这一目标。 我试过如下:

 公共类PagerAdapter扩展FragmentPagerAdapter {
    私人诠释numOne = 0;
    私人诠释numTwo = 0;

    // ...

    @覆盖
    公共CharSequence的getPageTitle(INT位置){
        开关(位置){
        情况下0:
            返回列表1(+ numOne +);
        情况1:
            返回列表2(+ numTwo +);
        默认:
            返回 ;
    }

    公共无效setNumOne(INT NUM){
        this.numOne = NUM​​;
    }

    公共无效setNumTwo(INT NUM){
        this.numTwo = NUM​​;
    }
}
 

当我现在叫 setNumXXX()的方法,没有任何反应,直到我动片段之间,似乎什么触发 getPageTitle()火。

我的问题是:如何强制标题(S),每次的更新时, NUM 价值变动

解决方案

如果你调用 notifyDataSetChanged()上的指示灯比如,它会重绘自己和抓住新的头衔。

My current project uses some ListFragments to show rows of data. The rows get updated dynamically every some seconds. The amount of rows varies with every update and in every ListFragment.

I would like to show the amount of rows to the user, and think that the perfect place for that would be next to the Fragment's title in the ViewPagerIndicator. I provided a sample image for better comprehension:

Sadly I am pretty clueless how to achieve this. I tried the following:

public class PagerAdapter extends FragmentPagerAdapter {
    private int numOne = 0;
    private int numTwo = 0;

    // ...

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
        case 0:
            return "List 1 (" + numOne + ")";
        case 1:
            return "List 2 (" + numTwo + ")";
        default:
            return "";
    }

    public void setNumOne(int num) {
        this.numOne = num;
    }

    public void setNumTwo(int num) {
        this.numTwo = num;
    }
}

When I now call the setNumXXX() method, nothing happens, until I move between fragments, what seems to trigger the getPageTitle() to fire.

My question is: How can I force an update of the title(s), everytime when the num value changes?

解决方案

If you call notifyDataSetChanged() on the indicator instance it will redraw itself and grab the new titles.

这篇关于动态更改ViewPagerIndicator冠军的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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