简体   繁体   中英

refresh tabs fragment and viewpager

I setup my viewpager according to the data I get from my database. If there are 3 person, I setup 3 tabs. Now through settings, I can add a delete a person. I want to reload the tabs according to the updated data. I know onResume is called again when my fragment is accessed. I'm doing this but this is not refreshing the tabs, they should have one less or one more tab depending on the update in database.

 @Override
    public void onResume(){
        super.onResume();
        Log.d("Refresh", " "+ MainActivity.allowRefresh);
        if (MainActivity.allowRefresh)
        {

            MainActivity.allowRefresh = false;

            setupViewPager(viewPager);
            tabLayout.setupWithViewPager(viewPager);
        }


    }

No need to re attached the viewpager with tablayout. Change the dataset that you use in your viewpager.setAdapter(adapter) and call adapter.onDataSetChanged()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM