【发布时间】:2020-01-26 07:27:54
【问题描述】:
我正在尝试显示一些具有不同布局的文档和图像的 ListView。 它适用于文档,但图像仍未显示。 我使用 .contains 方法来检查项目是文档还是图像。帮我解决这个问题。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = activity.getLayoutInflater();
String fileName = uriList.get(position).getFileName();
return viewSetup(position, layoutInflater, fileName);
}
private View viewSetup(final int position, LayoutInflater layoutInflater, String fileName) {
if (fileName.contains(".png") || fileName.contains(".jpg") || fileName.contains(".jpeg")) {
View inflate = layoutInflater.inflate(R.layout.main_list_item_img, null, false);
ImageView imageView = inflate.findViewById(R.id.imgPrev);
Glide.with(activity).load(uriList.get(position).getDownloadLink()).into(imageView);
itemSetup(position, fileName, inflate);
return inflate;
} else {
View inflate = layoutInflater.inflate(R.layout.main_list_item_docs, null, false);
itemSetup(position, fileName, inflate);
return inflate;
}
}
private void itemSetup(final int position, String fileName, View inflate) {
TextView title = inflate.findViewById(R.id.uriTitle);
TextView desc = inflate.findViewById(R.id.uriDesc);
ImageView download = inflate.findViewById(R.id.download);
TextView createdOn = inflate.findViewById(R.id.createdOn);
title.setText(fileName + "");
desc.setText(uriList.get(position).getDescription());
createdOn.setText(uriList.get(position).getSendTime());
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
savefile(uriList.get(position).getDownloadLink());
}
});
}
【问题讨论】:
-
尝试调试,如果它跳转到膨胀 main_list_item_img
-
粘贴任意图片的下载链接。
-
“uriList.get(position).getDownloadLink()”是否返回正确的 url?也请回复@AlexMamo
标签: java android firebase android-studio google-cloud-firestore