I have a ListView, displaying some items, containing an ImageView filled with a standard image at first and a line of text.
What I wanna do is downloading one thumb after another with an AsyncTask and step for step change the standard image with the downloaded one. How to realise this?
The ListView contents are managed by an enhanced ArrayAdapter.
greetz
EnflamedSoul
If I understand you correctly you're interested in a LazyList. This example shows a stub for the image, then downloads some thumbnails as the user scrolls down and caches these onto an SD card. The next time the images will be loaded from the SD card.
Lazy load of images in ListView
I personally used Fedor's example and it worked well.
Related
I have a long list of images that i need to show in to recyclerView. I am using glide to show the images from my adapter.
Glide.with(context).load(feed.getImgLink()).diskCacheStrategy(DiskCacheStrategy.NONE).into(holder.myImgView);
The above is the code am using i set the DiskCacheStrategy to none because I'm trying to show Instagram like Feed and i didn't want to permanently cache the img on disk.
The first time i see the image there is no problem it is displayed normal but after i scroll down and back up the image reload again. I get that i haven't cache the image in to disk but there is still momery cache.
Is there any way i can solve i could use diskcache to ALL but it is taking space for just one time viewing.
Try this.
Glide.with(context).load(imageUrl).into(holder.myImgView);
How can I create a ListView of videos?
I explain myself a little better, I want to make an app with a listview that contains short videos.
I create an activity list_item where I want to put images and text. For example in the first list item I want you to put a thumbnail and a description, for example: horse accident and in the second list_item put another thumbnail with another description, for example: squirrel attack.
I know how to create a list view that shows the same image in all the list_items, but I don't know how to make a list view that contains different videos, images and text for each list_item.
The images, the video and are stored in the assets and raw folder, respectively.
Do you have any idea how to fix this?
Use this library for videos using ListView :
implementation 'cn.jzvd:jiaozivideoplayer:6.2.12'
use this link for documentation : https://github.com/lipangit/JiaoZiVideoPlayer
This is more a question of application logic and performance.
Project Setup: I have an Android ListView which inflates a layout that is more aesthetically pleasing than just simple text. In each row (7 to be exact), I have an Image that is fetched by URL.
The problem: This ListView and its data are set by an ArrayList of model objects that serve as temporary data holders. When the rows are added the model objects are then used to set the data in the specific row's UI. The issue then comes along, that when a user scrolls down on the list a row that was once viewable is now out of the user's view. When the user scrolls back up to that row, the whole process of fetching the Image then happens again.
This seems like it can be avoided by instead of passing URLs through the models then fetching the images, I should fetch the images first, then pass the bitmaps to the model, therefore when the row is visible again to the user, it does not have to re-load the image.
Is there a way to write an AsyncTask that can load 7 images successfully, or do I have to create an AsyncTask object for each image?
Everytime I go this route the application crashes...
You can use Picasso library for this task.
Visit http://square.github.io/picasso/
In the adapter of your ListView, in the method getView, you can put this:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_error)
.resizeDimen(R.dimen.list_detail_image_size,R.dimen.list_detail_image_size) .centerInside()
.into(imgView);
You dont need a AsyncTask because this library already implements itself.
I am trying to insert multiple images in one editText. I have used following code to attach image to EditText
txt = (EditText)findViewById(R.id.text);
Bitmap bitmap = BitmapFactory.decodeFile(attach);
Drawable drawable = new BitmapDrawable(bitmap);
txt.setBackgroundDrawable(drawable);
But the problem is it only attach one file and show, If i used array then only the last image is only show. at any how it only shows one Image. Is there any way to show multiple images in one Editbox. Thanks in advance.
Because you can only have one background.... if you want more then there is a layer Drawable which you can use and also you can put the button in a frame layout and add a couple of imageViews below/over it for the rest of the images.
But the best solution will probably be instead of having a couple of bitmaps to just make a single one in Photoshop or equivalent photo editing app and place that one.
According to docs: http://developer.android.com/reference/android/view/View.html#setBackgroundDrawable(android.graphics.drawable.Drawable)
You are not able to provide more than one Drawable item in argument
And I don't know if you understand what is .setBackgroundDrawable(d) method purpose, but it is not meant to be used for displaying images inside text but to set Background of EditText View.
So you're not inserting images in EditText but setting its background,
look for some Rich Text Edit components usable for Android
such as http://code.google.com/p/android-richtexteditor/
or others..
You can probably use a LayerDrawable with the constructor LayerDrawable(Drawable[] layers) to chain together several images and display them as an EditText's background, though as Marek said, I suspect you're looking for something other than setting images in the background.
I'm making an application that reads a bunch of images URL on a JSON string. With a new thread the app downloads the images to a specific directory. Then there is a "gallery" based on a GridView with an ImageAdapter that displays all the files. The thing is that it takes too long the first time to download all the images.
My goal is to display the images while they are downloading. Right now the user has to go back and then enter again in the gallery to view the new images. Until all the images are downloaded.
If someone has a workaround for this, let me know.
Thanks..
Once your images are downloaded call notifydatasetchanged on the adapter. This can be done either after every image or a set of images.
Edit : Assuming you are calling the thread in MainActivity and the adapter is being called in the Display Activity , you can have the downloading thread call a listener, defined in the Display activity which calls notifydatasetchanged.
Also I am hoping each image is downloaded in a separate thread :-)