Add Multiple ArrayLists to RecyclerView

时间秒杀一切 提交于 2019-12-13 09:39:53

问题


I am trying to list text and images in a list format in the recyclerview and display in each row this my code and I know its wrong cause its only showing one row how must I edit the code. Still learning java

ArrayList<DataList> dataList = new ArrayList<DataList>();

    for (int i = 0; i < 1; i ++ ) {

        dataList.add(new DataList(

                "France",
                "Russia",
                R.drawable.lt1,
                "America",
                "Europe",
                R.drawable.lt2
        ));
    }

    ArrayList<DataList2> dataList2 = new ArrayList<DataList2>();

    for (int i = 0; i < 1; i ++ ) {

        dataList2.add(new DataList2(

                "South Africa",
                "Brazil",
                R.drawable.lt1,
                "New Zeland",
                "Pakistan",
                R.drawable.lt2
        ));
    }

回答1:


You are iterating the loop only 1 time .

for (int i = 0; i < 1; i ++ ) {
                    /\
                    ||
                 Iterate it more times
}

Like

for (int i = 0; i < n; i ++ ) {// n times or as much as you want 

}



回答2:


You should be adding them to one main ArrayList of items which the RecyclerView will then show.



来源:https://stackoverflow.com/questions/29205965/add-multiple-arraylists-to-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!