gpt4 book ai didi

android - 将 simpleAdapter 与图像一起用于 ListView

转载 作者:行者123 更新时间:2023-11-29 00:34:23 25 4
gpt4 key购买 nike

我在使用简单适配器将图像放入 ListView 时遇到了一点问题。我从我的在线服务器 (AMAZON) 获取图像。根据用户 ID 下载图像后,我尝试在我的 ListView 中设置它们,但没有显示任何内容,也没有发生错误。

下面是我的代码:

// looping through All applicants
for (int i = 0; i < applicant.length(); i++) {
JSONObject c = applicant.getJSONObject(i);

// Storing each JSON item in variable
String uid = c.getString(TAG_UID);
String name = c.getString(TAG_NAME);
String overall = c.getString(TAG_OVERALL);
String apply_datetime = c.getString(TAG_APPLY_DATETIME);
String photo = c.getString(TAG_PHOTO);

// creating new HashMap
//HashMap<String, String> map = new HashMap<String, String>();

//IMAGE
HashMap<String, Object> map = new HashMap<String, Object>();

// adding each child node to HashMap key (value)
map.put(TAG_UID, uid);
map.put(TAG_NAME, name);
map.put(TAG_OVERALL, overall);
map.put(TAG_APPLY_DATETIME, apply_datetime);

// adding HashList to ArrayList
// applicantsList.add(map);

// LISTING IMAGE TO LISTVIEW
try {
imageURL = c.getString(TAG_PHOTO);

InputStream is = (InputStream) new URL(
"my url link/images/"
+ imageURL).getContent();
d = Drawable.createFromStream(is, "src name");
} catch (Exception e) {
e.printStackTrace();
}

map.put(TAG_PHOTO, d);

// adding HashList to ArrayList
applicantsList.add(map);
}

如您所见,在我下载图片后。我使用下面的 simpleAdapter 设置为 ListView :

 SimpleAdapter adapter = new SimpleAdapter(
SignUpApplicantActivity.this, applicantsList,
R.layout.list_applicant, new String[] {
TAG_UID, TAG_NAME, TAG_OVERALL,
TAG_APPLY_DATETIME, TAG_PHOTO }, new int[] {
R.id.applicantUid, R.id.applicantName,
R.id.applicantOverall,
R.id.apply_datetime, R.id.list_image });
// updating listView
setListAdapter(adapter);

最佳答案

你调用了 notifyDatasetChange() 了吗?如果您不调用它,您的适配器可能不会失效。

关于android - 将 simpleAdapter 与图像一起用于 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com