How to group items within RecyclerView when using FlexboxLayoutManager

38 Views Asked by At

I am making a simple quiz-like app where the player needs to guess a set of words based on some clues. The placeholder for the words is managed using a RecyclerView where each item corresponds to one letter of the hidden words. I am using FlexboxLayoutManager to handle the layout of the keys. What I am struggling with is how to display the hidden text in a way that individual words are not split onto two lines. Please see the images below to see what I mean.

Current output: Desired output:

Basically I would like the FlexboxLayout manager to treat each word as one wide cell and only wrap around the spaces (which are also keys).

FlexboxLayout code:

private void setRecyclerViewData() {


        FlexboxLayoutManager gridLayoutManager = new FlexboxLayoutManager(this);
        gridLayoutManager.setFlexDirection(FlexDirection.ROW);
        gridLayoutManager.setJustifyContent(JustifyContent.CENTER);

        recyclerViewLogoKeys.setLayoutManager(gridLayoutManager);
        recyclerViewLogoKeys.setHasFixedSize(true);
        adapterLogo = new RecyclerView_Logo_Keys(arrayList_Logo);
        recyclerViewLogoKeys.setAdapter(adapterLogo);

RecyclerView:

public class RecyclerView_Logo_Keys extends RecyclerView.Adapter<RecyclerView_Logo_Keys.ViewHolder> {

        private final ArrayList<ArrayList_Logo> arrayList_Recycler1;


        public RecyclerView_Logo_Keys(ArrayList<ArrayList_Logo> mArrayList) {
            arrayList_Recycler1 = mArrayList;
        }


        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_key_logo, parent, false);
            return new ViewHolder(v);
        }
        
        @Override
        public void onBindViewHolder(final ViewHolder holder, @SuppressLint("RecyclerView") final int position) {

            String nullChar = arrayList_Recycler1.get(position).getNullChar();
            String trueChar = arrayList_Recycler1.get(position).getCharacter();

            holder.textViewKey.setText(nullChar);

            int type = arrayList_Recycler1.get(position).getTypeCharacter();

            // more code ....
            // ...

        }
}

Any help or pointing in the right direction will be much appreciated!

Thanks.

0

There are 0 best solutions below