Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在像wats应用程序这样的片段中显示数据时,如何更新选项卡布局徽章计数?_Java_Android_Android Fragments_Android Tablayout_Badge - Fatal编程技术网

Java 在像wats应用程序这样的片段中显示数据时,如何更新选项卡布局徽章计数?

Java 在像wats应用程序这样的片段中显示数据时,如何更新选项卡布局徽章计数?,java,android,android-fragments,android-tablayout,badge,Java,Android,Android Fragments,Android Tablayout,Badge,我遵循这一点,并将通知添加到选项卡布局中,我的问题是如何在类似wats应用程序的片段页面中更新徽章计数器。 我尝试了下面的代码,以便在选项卡布局活动中工作正常,但我不知道如果对象计数大小增加,如何在片段中设置数字增量?请帮忙。我的代码如下 ApiUtil.getServiceClass().getDiscussion(demo, RTFA + "; FedAuth=" + FedAuth).enqueue(new Callback<Discussion>() { @R

我遵循这一点,并将通知添加到选项卡布局中,我的问题是如何在类似wats应用程序的片段页面中更新徽章计数器。 我尝试了下面的代码,以便在选项卡布局活动中工作正常,但我不知道如果对象计数大小增加,如何在片段中设置数字增量?请帮忙。我的代码如下

ApiUtil.getServiceClass().getDiscussion(demo, RTFA + "; FedAuth=" + FedAuth).enqueue(new Callback<Discussion>() {
        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public void onResponse(Call<Discussion> call, Response<Discussion> response) {
            List<com.com.ideaentity.csp.daoutils.discussiondao.Result> result=response.body().getD().getResults();
            discussion=result.size();
            updateDiscussin(discussion);

                       }

           @Override
        public void onFailure(Call<Discussion> call, Throwable t) {

        }
    });

    ApiUtil.getServiceClass().getMyDocs(dosurl,RTFA + "; FedAuth=" + FedAuth).enqueue(new Callback<MyDocs>() {
        @Override
        public void onResponse(Call<MyDocs> call, Response<MyDocs> response) {
            if (response.isSuccessful()){
                // myDocsList.setValue(response.body().getD().getMyDocsResults());
                List<com.com.ideaentity.csp.daoutils.mydocs.Result> myDocsResultList=response.body().getD().getFiles().getResults();

              documents=myDocsResultList.size();
              updatevalue(documents);

            }else {
            }

        }

        @Override
        public void onFailure(Call<MyDocs> call, Throwable t) {

        }
    });



    if (getSupportActionBar() != null){
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    String category=Utils.getFromSharedPreference("category");

    viewPager = findViewById(R.id.container);
    viewPager.setAdapter(mSectionsPagerAdapter);
    tabLayout =findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));



    if (discussion!=null&&documents!=null){


    }

}
 public void updateDiscussin(Integer discussion) {
    BadgeDrawable badgeDiscussion = 
   tabLayout.getTabAt(2).getOrCreateBadge();
    badgeDiscussion.setVisible(true);
    badgeDiscussion.setNumber(discussion);
    badgeDiscussion.setBackgroundColor(getResources().getColor(R.color.floating_button_color));
}

private void updatevalue(Integer discussion) {
    BadgeDrawable badgeDocuments   = 
    tabLayout.getTabAt(3).getOrCreateBadge();
    badgeDocuments.setVisible(true);
    badgeDocuments.setNumber(discussion);
    badgeDocuments.setBackgroundColor(getResources().getColor(R.color.floating_button_color));

}

    badgeDiscussion.setBackgroundColor(getResources().getColor(R.color.floating_button_color));
}

tabLayout在片段中可用吗?@GabrieleMariotti没有选项卡布局在片段中不可用据我所知,我们只能在宿主活动中使用选项卡布局类对象。
 Integer count=myDocsResultList.size();
                BadgeDrawable badgeDrawable = BadgeDrawable.create(getContext());
                badgeDrawable.setNumber(count);