Skip to content

Commit

Permalink
Fix labexp#479: Added a check to prevent duplicate DividerItemDecorat…
Browse files Browse the repository at this point in the history
…ion in RecyclerView setup
  • Loading branch information
miltonials committed Dec 8, 2024
1 parent 140538a commit 577b10f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/src/main/java/net/osmtracker/activity/TrackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -139,19 +142,21 @@ protected void onResume() {


/**
*
* Configures and initializes the RecyclerView for displaying the list of tracks.
*/
private void setRecyclerView() {
RecyclerView recyclerView = findViewById(R.id.recyclerview);

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,
Expand Down

0 comments on commit 577b10f

Please sign in to comment.