【发布时间】:2013-07-19 06:18:18
【问题描述】:
我在尝试调用 ImageLoader 的 DisplayImage 函数时遇到问题,实际上没有得到我需要使用 显示图像:
imgLoader.DisplayImage (....);
我正在编写一个应用程序,我需要在其中将图像加载到 ImageView 中,但总是在 Image 的位置出现空白,请参见下图:
注意:我不知道我需要使用什么,在这一行:
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(url, loader, imageView);
所以请给我看代码,我需要写什么来在 ImageView 中显示图像, 根据我的代码
我正在使用 Localhost 来获取图像,请参阅下面的代码用于获取图像-
private static final String URL_ALBUMS = "http://10.0.2.2/songs/albums.php";
private static final String TAG_IMAGE = "imagepath";
String image = c.getString(TAG_IMAGE);
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_IMAGE, image);
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all albums
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
AlbumsActivity.this, albumsList,
R.layout.list_item_albums, new String[] { TAG_ID,
TAG_NAME, TAG_IMAGE, TAG_SONGS_COUNT },
new int[] {
R.id.album_id, R.id.album_name, R.id.list_image, R.id.songs_count });
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
// here i don't know how to call DisplayImage function
imgLoader.DisplayImage (....); // what to write here
// updating listview
setListAdapter(adapter);
}
});
注意-我已经在我的项目中添加了所有必需的类,类是:
ImageLoader.java, FileCache.java, MemoryCache.java & Utils.java
data.php:-
1 => array(
"id" => 1,
"album" => "127 Hours",
"imageurl" => "images/onetwentyseven.png"
............
注意:- 如您所见,我使用的是 本地图像,我将这些图像存储在 localhost in images 文件夹中。
JSON:-
[{"id":1,"name":"127 Hours","imagepath":"images\/onetwentyseven.png","songs_count":2},{"id":2,"name":"Adele 21","imagepath":"images\/adele.png","songs_count":2}]
【问题讨论】:
-
你的图片是否正确显示在浏览器中
-
@Stacks28 是的,我可以在我保存的本地主机路径中看到我的图像
-
你的清单中是否有写外部存储权限。
标签: android json image-loading