I have a ListActivity that should display quite a lot of items and where each list item should contain a text and and an image. The images are gotten from a remote server. How can I display the remote image on the list item. Thanks in advance
Download the images into memory or a local cache using HttpURLConnection or similar then use BitmapFactory.decodeByteArray to convert the downloaded images into bitmaps and assign them to ImageViews using setImageDrawable to display them.
Related
I want to load image from SQLite DB in my android app and set its values into a image slider (viewpager) similar this tutorial :
http://www.thecrazyprogrammer.com/2016/12/android-image-slider-using-viewpager-example.html#comment-49936
please help !
You first need to save your images in database in form of byte[] and then retrieve one by one in your pager adapter then convert byte[] to Bitmap and set in ImageView. But this is not a good practice.
If your images are static then you should store them in drawables as shown in that tutorial and if your images are dynamic and fetched from network you should use Picasso, Glide or any such library to load those images directly from network into your ImageView.
This tutorial might help you in integrating Picasso library.
What I have
I have GridLayoutManager Recyclerview which has positions 0,2,5,7 fixed with custom images (relative layout converted to bitmap ;) ) , rest positions are filled with images from server using volley's setImageUrl()
What I want
I wanted the GridLayoutManager Recyclerview to show offline images from my drawable folder using setDefaultImageResId() till the images from server loads
My problem
How do I set different default images even when there is no images from server reason (when there is no data from server , the GridLayoutManager Recyclerview doesn't populates cells) , still I wanted to show default images (mini 4 cells required)
temporary trick I did
I upploaded my 4 defaults images in dummy server to force GridLayoutManager Recyclerview to generate cells and showing it using volley's setImageUrl()
My expected result
I think that Volley has the option to display a default image and a image if an error has occurred.
NetworkImageView niv = (NetworkImageView)findViewById(R.id.niv);
if(url.length() > 0)
niv.setImageUrl(url, imageLoader);
niv.setDefaultImageResId(R.drawable._default);
niv.setErrorImageResId(R.drawable.error);
You can use the Picasso library for loading the images from the server. Using Picasso, you can determine an image to be shown in case of a network error, or if no data is available.
Picasso.with(context).load(url).error(R.drawable.error_or_defaultimage).into(R.id.imageview,callback) ;
Here's a tutorial on using Picasso.
I am working on requirement of loading images to custom list view in android. I am getting the data from server in bytes format.
While loading that data to list view and display its missing smooth scrolling. Can any please help me to come out of this problem and how to cache this images to increase the performance?
I am getting URL string of image in one response, Then i am downloading those images and converting tobitmaps then displaying in listview.
Here my question is in future listview items may increase upto 50000,in this case how can i handle data in listview for smooth scroll without giving ANR Exception.Please provide some sample code.
Dont Load All Images At a Time.... It will cause OutOfMemoryException..you can load images in number of pages from URL....
To download images from URL you can use Picasso library...
It helps you to avoid OutOfMemoryException and store cache of images too..
You can use LAZY LOAD... and you can try this code for download images...
Picasso.with(context).load(URL).fit().centerCrop().into(imageView);
Simple answer dont make a listview so big. 50K elements in a single screen is never a good idea in any scenario(web, desktop or mobile). My suggestion is to have some sort of pagination just like in websites. As for the images like #Prag suggested above use lazy loading for showing images. In my app I used Universal Image Loader and find it extremely useful for showing a large number of bitmaps.
I want to display thumbnail image as image icon in ListView.
I am using array list that contains all thumbnail images path, these path will be accessed from the server.
My arraylist as ahown below.
mylist=['a1','a2','/playback/2012/a1.jpg','b1','b2','/playback/2012/000_b1.jpg', .....]
In this nearly 15 paths are there.. Now i want to display these images in listview.
'a1' is videoName 'a2' is categoryName and one more is path.
These path will be accessed from server only.. I think, we can't store it in drawable.
These are always changing.
How to solve it?
Please help me.
Use ImageView in the layout for ListView items and load images as described here:
How to load an ImageView by URL in Android?
and optionally here:
Lazy load of images in ListView