@@ -84,6 +84,9 @@ public class TrackManager extends AppCompatActivity
84
84
85
85
private TrackListRVAdapter recyclerViewAdapter ;
86
86
87
+ // To check if the RecyclerView already has a DividerItemDecoration added
88
+ private boolean hasDivider ;
89
+
87
90
@ Override
88
91
protected void onCreate (Bundle savedInstanceState ) {
89
92
super .onCreate (savedInstanceState );
@@ -139,19 +142,21 @@ protected void onResume() {
139
142
140
143
141
144
/**
142
- *
145
+ * Configures and initializes the RecyclerView for displaying the list of tracks.
143
146
*/
144
147
private void setRecyclerView () {
145
148
RecyclerView recyclerView = findViewById (R .id .recyclerview );
146
149
147
150
LinearLayoutManager layoutManager = new LinearLayoutManager (this ,
148
151
LinearLayoutManager .VERTICAL , false );
149
152
recyclerView .setLayoutManager (layoutManager );
150
-
151
- DividerItemDecoration did = new DividerItemDecoration (recyclerView .getContext (),
152
- layoutManager .getOrientation ());
153
- recyclerView .addItemDecoration (did );
154
-
153
+ // adds a divider decoration if not already present
154
+ if (!hasDivider ) {
155
+ DividerItemDecoration did = new DividerItemDecoration (recyclerView .getContext (),
156
+ layoutManager .getOrientation ());
157
+ recyclerView .addItemDecoration (did );
158
+ hasDivider = true ;
159
+ }
155
160
recyclerView .setHasFixedSize (true );
156
161
Cursor cursor = getContentResolver ().query (
157
162
TrackContentProvider .CONTENT_URI_TRACK , null , null , null ,
0 commit comments