Viewbadger Count未动态更新

时间:2015-09-10 06:40:33

标签: android badge activity-lifecycle

当数据库通过任何操作更新时,viewbadger计数器未在DashboardActivity上更新。

public static BadgeView badge1;
public static BadgeView badge2;


@Override
public void onResume() {
    super.onResume();

      Badgeupdate(); // function to update badge           
}


public void Badgeupdate() {   

    neworders_count=0;     
    pendingorders_count=0;        


    badge1 = new BadgeView(this, v1); // v11 is View
    fetch_neworders_count();  // fetch data count query
    CurrentActivity.badge1.setText(neworders_count + "");
    badge1.show();

    badge2 = new BadgeView(this, v2); // v2 is View
    fetch_pendingorders_count();  // fetch data count query
    CurrentActivity.badge2.setText(pendingorders_count + "");
    badge2.show();  



}

我有用户Viewbadger库 - https://github.com/jgilfelt/android-viewbadger

enter image description here

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

public static BadgeView badge1;
  badge1 = new BadgeView(MainActivity.this, v1); //v1 is view selected to set badge

            badge1.setText("0");
            badge1.show();

MainActivity.badge1.setText("hello badge"); //call it from anywhere to update

在您的徽章更新中,只使用badge.setText(" hello");没有更多的东西,你在这里一次又一次地创造它们。