I don't know what to put inside "this", "R.id.fragment_container" or "currentFragment" to make the code work. I have one activity with tabs and therefor three Fragments. In this "MainActivity" i want to update the view of a fragment. The code is inside the MainActivity.
Here are two variants of refreshing a fragment by stackoverflow.
In Refresh or force redraw the fragment it says "To refresh ListView you need to call notifyDataSetChanged() on the ListView's adapter." How to do this?
Variant 1
Fragment currentFragment = getActivity().getFragmentManager().findFragmentById(R.id.fragment_container);
if (currentFragment instanceof "NAME OF YOUR FRAGMENT CLASS") {
FragmentTransaction fragTransaction = (getActivity()).getFragmentManager().beginTransaction();
fragTransaction.detach(currentFragment);
fragTransaction.attach(currentFragment);
fragTransaction.commit();}
}
Variant 2
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
getFragmentManager().beginTransaction().detach(this).commitNow();
getFragmentManager().beginTransaction().attach(this).commitNow();
} else {
getFragmentManager().beginTransaction().detach(this).attach(this).commit();
}
Can you help me make the code work? In "this" there is a fragment expected.