Reputation: 131
I'm trying to load many picture from internet in many imageView with progressBar.I succeed to do it but the problem all the images are loaded in the first imageView (as slider).but I don't know to to make it correct I mean to download each picture in one imageView:
Upvotes: 0
Views: 119
Reputation: 1005
I was working on a project like this. I used this lazy loader and got success.
Upvotes: 1
Reputation: 15543
Add a parameter to your DownloaderAsyncTask
s constructor. Use it at onPostExecute
int mIndex;
public DownloaderAsyncTask(Context context, int index) {
mContext = context;
mIndex = index;
}
protected void onProgressUpdate(Integer... progress) {
Intent intA = new Intent("...");
intA.putExtra("resultCounter", mIndex );
intA.putExtra("int", progress[0]);
context.sendBroadcast(intA);
}
protected void onPostExecute(ByteArrayBuffer result) {
Intent intB = new Intent("....");
intB.putExtra("resultCounter", mIndex );
intB.putExtra("image", result.toByteArray());
context.sendBroadcast(intB);
}
Change initialization of asynctasks with your new constructor.
for(int i = 0; i < 5; i++) {
DownloaderAsyncTask asyncTask = new DownloaderAsyncTask(getApplicationContext(), i);
asyncTask.execute(links[i]);
}
Also change the to resultCounter tag when you get progCounter value
// Broadcast receiver for PROGRESS BAR
BroadcastReceiver receiveProgress = new BroadcastReceiver(){
public void onReceive(android.content.Context context, Intent intent) {
int progress = intent.getIntExtra("int", 0);
int progCounter = intent.getIntExtra("resultCounter", 0);
}
Upvotes: 1
Reputation: 6925
This is your mistake
In your BroadcastReceiver receiveImage
You are trying to get the value of progCounter from the intent.
int progCounter = intent.getIntExtra("resultCounter", 0);
But in your Async Task you are not sending any intent of resultCounter so each time you trying to get the value of intent it will give you 0 ("resultCounter", 0) as no intent is there.
Upvotes: 0