问题
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