使用Java 8 forEach将视图添加到表行中

问题描述 投票:0回答:1
TableRow tableRow = new TableRow(getContext());
List<File> threeFiles = listOfFiles.subList(i, i+2);
threeFiles.forEach(action ->  tableRow.addView(new ImageView(getActivity().getApplicationContext()).setBackground(Drawable.createFromPath(action.getAbsolutePath()))));

最后一行说,ViewGroup中的addView(android.view.View)无法应用于(void)。如何使用Java 8 ForEach将带有文件源的Views添加到表行?我正在尝试更多地使用Java 8 Streams以使我的代码更简洁]

android foreach collections java-8 stream
1个回答
0
投票

您的问题是在末尾添加setBackground使该行返回空,因为setBackground返回空,您可能需要像这样吐出这行:

© www.soinside.com 2019 - 2024. All rights reserved.