Sort items in a RecyclerView using StaggeredGridLayoutManager

1

I am creating an application where users create elements with an image and they are displayed as a list. It looks like Google Keep, where the elements created do not have the same height but the same width, distributed in two columns. The order in which the elements are created is important and should be arranged in that way, from top to bottom. As shown in the photo, each number represents the order in which the elements were created, it is not ordered in the expected way.

Is there any way in which you can define how the elements should be ordered? I'd like to sort them:

1 2

3 4

5

and so on.

This is the code snippet where I initialized the RecyclerView, the adapter and the Layout Manager:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
AdapterRecyclerView adapterRecyclerView = new AdapterRecyclerView(getContext(), list);
recyclerView.setAdapter(adapterRecyclerView );
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
    
asked by Ramin 27.03.2018 в 04:49
source

0 answers