D
D
DARKENN2019-09-25 00:11:38
Java
DARKENN, 2019-09-25 00:11:38

How to make the required number of cards and give each a random picture?

package com.example.parallax.Game;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.parallax.R;

import java.util.ArrayList;

public class Winners extends Fragment {

    private RecyclerView recyclerView;
    private ArrayList<WinnerModel> imageModelArrayList;
    private WinnerAdapter adapter;

    private int[] myImageList = new int[]{R.drawable.winner1, R.drawable.winner2,R.drawable.winner3, R.drawable.winner4};
    private String[] myImageNameList = new String[]{"Данила","Виталий" ,"Андрей","Тест", "Тест2", "Тест3"};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_winners, container, false);

        recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler);

        imageModelArrayList = winners();
        adapter = new WinnerAdapter(getActivity(), imageModelArrayList);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));

        return rootView;
    }

    private ArrayList<WinnerModel> winners(){

        ArrayList<WinnerModel> list = new ArrayList<>();
        for(int i = 0; i < 6; i++){
            WinnerModel fruitModel = new WinnerModel();
            fruitModel.setName(myImageNameList[i]);
            fruitModel.setImage_drawable(myImageList[i]);
            list.add(fruitModel);
        }
        return list;
    }

}

I will get the number of winners from the database, but it’s not clear to me how to make the required number of cardviews so that it itself adjusts to the number of winners, and they were given random pictures from 4 given ones and given names from the firebase database

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question