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以使我的代码更简洁]
您的问题是在末尾添加setBackground
使该行返回空,因为setBackground
返回空,您可能需要像这样吐出这行: