loading different offline images (default images ) in NetworkImageview Volley android - android

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.

Related

RecyclerView stutters when scrolling only 14 images

I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).

Load image from url to Recyclerview

I have an app that loads content from a database as well as images from the internet. I am using a RecyclerView along with CardView to display my content in a list form.
Each row has an image on the left side and text on the right.
The problem is that the text loads fast but the image takes time to load, so I want the image to continue loading in the background and then load into the ImageView object once loading is complete. I have no idea how to tackle this.
I use Picasso for this situation, but u can also use Glide and many more libraries. The documentation is pretty simple.
Try Picasso:http://square.github.io/picasso/
It's a one liner in onBindViewholder():
Picasso.with(context).load(url).into(viewHolder.imageView);

Using volley to populate a fragment

I am working on a simple app and I am having issues understanding how to use volley for something I feel should be an easy task. Currently I have gotten volley to grab a json array that populates a list of images with titles next to them. The problem is I want to be able to press on an item in the list and spawn a new fragment with a larger version of the image in it. This seems like a really basic task, but I can't seem to find the right way to do it. If I grab the full images to create the list view, I run out of memory. I started grabbing thumbnail images, but then when I create the fragment, the view is inflated before the request for the image finishes. What is the right way to do this?
You can specify a placeholder image while Volley downloads your image, and an error image if the download wasn’t successful. In your situation, you can use your thumbnail image as the placeholder image.
The Making Image Request section in this artcle shows the good way to handle image request with Volley.
Sample code:
// Loading image with placeholder and error image
imageLoader.get(Const.URL_IMAGE, ImageLoader.getImageListener(
imageView, YOUR_THUNMBNAIL_IMAGE, R.drawable.ico_error));

Loading Sign before downloading Image and Setting Image on Image View

I have a listView in which I have text and an image view Now the data is coming from the service in this case text is of some bytes but due to images size imageview populate after some time . for this I want to show loading symbol in in imageview so that in time of downloading user not say that the app is not able to show images. I have implemented all listActivity and adapters concepts and its working fine but the images take time due to which the imageview part shows black area . any help
Here this I want:
In Android we called it lazy list..
this will help you to understood..
1.Lazy loading of images in ListView
2.http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/
For Image issue :
Change in ImageLoader class (if Using Lazy List)
final int stub_id=R.drawable.ic_launcher; //change it to process image
Good Luck
Place a ProgressBar and keep the imageView over the ProgressBar.So the progress bar is visible when there is no image in the image view. Also use lazyList to load image.
You might want to check out Android Query. it's a library that also supports Asynchronous image loading and caching.
Android

ListActivity Item with remote image

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.

Categories

Resources