I am building an AsyncTask
and I need to pass multiple images to multiple ImageView
containers.
I am trying to build the individual findViewById
as "img" + position
(an int that changes for each image)but my getResources()
does not work.
I have tried passing a context to my AsyncTask
when I instantiate it but it gives the same error.
Main Activity
while(i<20) {
for(String imgURL : imagePaths) {
new ImageDownloader(new WeakReference<AppCompatActivity>(this),i,getApplicationContext()).execute(imgURL,fpath);
i++;
}
}
AsyncTask
public class ImageDownloader extends AsyncTask<String, Integer, Bitmap> {
int position;
private WeakReference<AppCompatActivity> caller;
private final Context contextRef;
public ImageDownloader(WeakReference<AppCompatActivity> caller, Integer position, final Context context) {
this.caller = caller;
this.position = position;
this.contextRef = context;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
AppCompatActivity activity = caller.get();
Context context = contextRef;
if (context != null) {
int place = context.getResources().getIdentifier("img" + position, "id", context.getPackageName());
ImageView imageView = activity.findViewById(place);
imageView.setImageBitmap(bitmap);
}
I keep getting compilation failed, error:
cannot find symbol static getResources