Reputation: 121
I'm passing two values from one fragment to another, using Bundle
.
The fragment that retrieves the values puts them in a Recycler View adapter.
I want to clear the bundler when the values are already passed from one fragment to another.
How can I clear it? This is my Bundler:
bundler.putStringArrayList("listOfImages", (ArrayList<String>) randomImagemPaisList);
bundler.putStringArrayList("listOfNames", (ArrayList<String>) randomNomePaisList);
fragment.setArguments(bundler);
I've tried to clear the bundler after transaction.commit
but even when I do that, no values are passed...
EDIT
As I told you, I'm passing through Bundler
two values from one fragment to another. For example, when a user writes "Po" in my SearchView, I query the Firebase DB results to show just the countries starting with "Po" and in my adapter it shows me 2 countries. But after that, if I search one more string like "ta", it shows me the previous countries and the new ones. I've tried to clear the lists in the adapter but the problem is that, in the values that are passed through Bundler
the old ones are not removed and the new ones are added after...
This is the fragment that receives the values and sets them in the Recycler View adapter
public class FilteredResultsFragment extends android.support.v4.app.Fragment {
ImageAdapter imageAdapter;
List<String> listOfImages = new ArrayList<>();
List<String> listOfNames = new ArrayList<>();
private RecyclerView recyclerView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View viewFilteredResults = inflater.inflate(R.layout.fragment_filtered_results, container, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
getActivity().getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
recyclerView = viewFilteredResults.findViewById(R.id.recyclerViewFiltered);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
imageAdapter = new ImageAdapter(listOfImages, listOfNames, getContext());
recyclerView.setAdapter(imageAdapter);
return viewFilteredResults;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getArguments() != null) {
listOfImages.clear();
listOfNames.clear();
listOfImages.addAll(getArguments().getStringArrayList("listOfImages"));
listOfNames.addAll(getArguments().getStringArrayList("listOfNames"));
Log.d("TESTETAMANHO","SIZE "+listOfNames);
//final Bundle bundler = new Bundle();
//bundler.remove("listOfImages");
//bundler.remove("listOfNames");
imageAdapter.notifyDataSetChanged();
}
}
}
Upvotes: 0
Views: 40
Reputation: 14670
Please use remove
method in your receiving Fragment
(after you no longer need these values):
getArguments().remove("listOfImages");
getArguments().remove("listOfNames");
Upvotes: 1