question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to refresh a fragment ?

See original GitHub issue

The user can add or delete the pages himself. In these pages I have an edittext (in fact I have more but it is the same case for all) which is the name of the page. If the user creates a page that it calls “page 1”, deletes it and creates another page immediately after it, which it calls “page 2”, the fragment will display the data on page 1 ".

onCreate method

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
    pages = new FragmentPagerItems(this);
    // here page.add
    adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages){
        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }
    };
    viewPager.setAdapter(adapter);
    viewPagerTab.setViewPager(viewPager);

My method for create a new fragment

pages.add(FragmentPagerItem.of(
                                        Pref.getList_points().get(Pref.get_size() - 1).getName(),
                                        FragmentConfigurationPoints.class,
                                        new Bundler().putInt("param1", Pref.get_size() - 1).get()
                                ));
adapter.notifyDataSetChanged( );
viewPagerTab.setViewPager(viewPager);

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
fWX228941commented, Oct 14, 2017

change FragmentPagerItemAdapter to FragmentStatePagerItemAdapter solve my issue

1reaction
fWX228941commented, Dec 21, 2017
		mAdapter = new FragmentStatePagerItemAdapter(getSupportFragmentManager(), items){				@Override
			public int getItemPosition(Object object) {
				return POSITION_NONE;
			}

		};
		mViewpager.setAdapter(mAdapter);

@dengxingwen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refresh Fragment at reload - android - Stack Overflow
Go to your navigation graph and find the fragment you want to refresh. Create an action from that fragment to itself. Now you...
Read more >
Fragment Refresh | by Taman Neupane - Medium
Today i am gonna talk about fragment communication or simply we can say how to refresh one fragment from another fragment in tab...
Read more >
Refresh/Reload/Re instantiate a Fragment in an android tab ...
In Activity: @Override. public void onTabSelected(ActionBar.Tab tab,. FragmentTransaction fragmentTransaction) {. // When the given tab is selected, ...
Read more >
Fragment Refresh from Containing Page - Oracle Blogs
Initially the fragment is not aware of the fact that the variable that was passed in when the fragment first rendered has changed....
Read more >
Refreshing Fragments | Relay
In order to manually refresh the data for a fragment, we need a query to refetch the fragment under; remember, fragments can't be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found