【发布时间】:2019-01-22 21:10:15
【问题描述】:
我正在使用 listview 来填充可供下载的讲座列表(368 个讲座)。
它正在显示无法离线使用的讲座的“下载”文本。
对于可用的讲座,我正在进行外部文件检查,然后更新 “下载”文本到“离线”,但在 ListView 中无法正常工作 并且值是重复的。
这是我的 getView 方法代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
view = inflater.inflate(R.layout.customlistview, null);
} else {
view = convertView;
}
TextView number = view.findViewById(R.id.lec_number);
TextView title = view.findViewById(R.id.lec_title);
TextView url = view.findViewById(R.id.url);
TextView filename = view.findViewById(R.id.filename);
// Textview I want to update, contains "Download" text
TextView download_text = view.findViewById(R.id.download_text);
HashMap<String, String> mList = new HashMap<>();
mList = List.get(position);
number.setText(mList.get("number"));
title.setText(mList.get("title"));
url.setText(mList.get("url"));
filename.setText(mList.get("file"));
// File check that I'm doing
File externalFile = new File(Environment.getExternalStorageDirectory() + "/Lectures By Sarfaraz A Shah Sb/" + mList.get("file"));
if(externalFile.exists()) {
download_text.setText("Available");
}
return view;
}
这是我的输出:
【问题讨论】:
-
如何以及在何处填充 ListView?您如何遍历数据以确定您更改文本的 Listview 项目?您的 Listview 适配器在哪里?您需要提供更多信息如何将数据传递给 Listview 以及如何遍历它。
-
@skryshtafovych 问题已解决,伙计。我切换到recyclerview。
标签: android android-studio listview