Reputation: 1051
I am facing problem while trying to call ImageLoader's DisplayImage function, actually not getting what i need to use to Display Image:
imgLoader.DisplayImage (....);
I am writing an App in which I need to Load an Image into ImageView, but always getting blank in place of Image, please see below image:
Note: I don't know what i need to use, in this line:
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(url, loader, imageView);
So Please just show me the code, what i need to write to show image in ImageView, according to my code
I am using Localhost to fetch Image, Please see below code using to get Images-
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);
}
});
Note- I have added all required classes in my Project, classes are:
ImageLoader.java, FileCache.java, MemoryCache.java & Utils.java
data.php:-
1 => array(
"id" => 1,
"album" => "127 Hours",
"imageurl" => "images/onetwentyseven.png"
............
Note:- As you can see, i am using local images, those i have stored in localhost in images folder.
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}]
Upvotes: 1
Views: 1993
Reputation: 1609
Try this code in AlbumsActivity.java :
ImageView thumb_image = (ImageView) findViewById(R.id.list_image);
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(TAG_IMAGE, thumb_image);
Upvotes: 2
Reputation: 2072
imageLoader = ImageLoader.getInstance();
configuration = ImageLoaderConfiguration
.createDefault(getActivity());
imageLoader.init(configuration);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.default_image)
.showImageForEmptyUri(R.drawable.default_image)
.showImageOnFail(R.drawable.default_image)
.cacheInMemory().cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565).build();
imageLoader.displayImage(user_bean.getmImage(), mProfileImage,
options);
Upvotes: 1
Reputation: 3140
Url = "Your image url" //ex:- www.abc.com/images/img.jpg
Drawable drawable = LoadImageFromWebOperations(Url);
imageView.setImageDrawable(drawable);
private Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.out.println("Exc=" + e);
return null;
}
}
Upvotes: 1