Skip to content

Commit 577b10f

Browse files
committed
Fix labexp#479: Added a check to prevent duplicate DividerItemDecoration in RecyclerView setup
1 parent 140538a commit 577b10f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/src/main/java/net/osmtracker/activity/TrackManager.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public class TrackManager extends AppCompatActivity
8484

8585
private TrackListRVAdapter recyclerViewAdapter;
8686

87+
// To check if the RecyclerView already has a DividerItemDecoration added
88+
private boolean hasDivider;
89+
8790
@Override
8891
protected void onCreate(Bundle savedInstanceState) {
8992
super.onCreate(savedInstanceState);
@@ -139,19 +142,21 @@ protected void onResume() {
139142

140143

141144
/**
142-
*
145+
* Configures and initializes the RecyclerView for displaying the list of tracks.
143146
*/
144147
private void setRecyclerView() {
145148
RecyclerView recyclerView = findViewById(R.id.recyclerview);
146149

147150
LinearLayoutManager layoutManager = new LinearLayoutManager(this,
148151
LinearLayoutManager.VERTICAL, false);
149152
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+
}
155160
recyclerView.setHasFixedSize(true);
156161
Cursor cursor = getContentResolver().query(
157162
TrackContentProvider.CONTENT_URI_TRACK, null, null, null,

0 commit comments

Comments
 (0)