I have an adapter class that handles displaying a list of thumbnail images. When the user clicks on a thumbnail, it retrieves an image from a URL and takes about a second to do so and displays it in a dialog fragment. Because of the delay, I want there to be a toast that says "fetching image". However, the toast does not appear until the dialog fragment displays, which is pointless.
I have tried moving the toast before and after the call to make a dialog fragment and still the same result. I have tried using an AsyncTask to synchronize the toast first and then the dialog fragment but still the same result.
Adapter class:
holder.viewThumbnail.setOnClickListener(v ->
{
FetchImage fetchImage = new FetchImage(MainActivity.mainActivity, rootView, position);
fetchImage.execute();
});
FetchImage class:
protected final Void doInBackground(WeakReference<Activity>... params)
{
if(MainActivity.animalList.get(position).getImage() == null)
{
MainActivity mainActivity = weakReferenceActivity.get();
if(mainActivity != null)
{
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(mainActivity, mainActivity.getString(R.string.fetching_image), Toast.LENGTH_SHORT).show());
}
}
return null;
}
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
MainActivity mainActivity = weakReferenceActivity.get();
if(mainActivity != null)
{
mainActivity.dialogShow(view, C.NO, C.DIALOG_IMAGE, "", "", position);
}
}
I also simply tried doing this in the adapter class without the AsyncTask route:
Adapter class:
holder.viewThumbnail.setOnClickListener(v ->
{
if(MainActivity.animalList.get(position).getImage() == null)
interfaceCommon.makeToast("fetching data", 1);
interfaceCommon.dialogShow(rootView, C.NO, C.DIALOG_IMAGE, "", "", position);
});
The interfaceCommon is simply a common interface to call methods in the Main Activity. I have one activity for this app and multiple fragments.