From 577b10f75c237872e53e18f187bcab07bfbbb525 Mon Sep 17 00:00:00 2001 From: Milton Barrera Date: Sat, 7 Dec 2024 23:43:20 -0600 Subject: [PATCH] Fix #479: Added a check to prevent duplicate DividerItemDecoration in RecyclerView setup --- .../net/osmtracker/activity/TrackManager.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/osmtracker/activity/TrackManager.java b/app/src/main/java/net/osmtracker/activity/TrackManager.java index c9738aa2..8da25573 100644 --- a/app/src/main/java/net/osmtracker/activity/TrackManager.java +++ b/app/src/main/java/net/osmtracker/activity/TrackManager.java @@ -84,6 +84,9 @@ public class TrackManager extends AppCompatActivity private TrackListRVAdapter recyclerViewAdapter; + // To check if the RecyclerView already has a DividerItemDecoration added + private boolean hasDivider; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -139,7 +142,7 @@ protected void onResume() { /** - * + * Configures and initializes the RecyclerView for displaying the list of tracks. */ private void setRecyclerView() { RecyclerView recyclerView = findViewById(R.id.recyclerview); @@ -147,11 +150,13 @@ private void setRecyclerView() { LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(layoutManager); - - DividerItemDecoration did = new DividerItemDecoration(recyclerView.getContext(), - layoutManager.getOrientation()); - recyclerView.addItemDecoration(did); - + // adds a divider decoration if not already present + if (!hasDivider) { + DividerItemDecoration did = new DividerItemDecoration(recyclerView.getContext(), + layoutManager.getOrientation()); + recyclerView.addItemDecoration(did); + hasDivider = true; + } recyclerView.setHasFixedSize(true); Cursor cursor = getContentResolver().query( TrackContentProvider.CONTENT_URI_TRACK, null, null, null,