サーバーからの画像を処理してImageView
に表示するために、AsyncTaskクラスを使用しています。コードに[次へ]ボタンが1つあり、次のコードを使用して次の画像を呼び出します。
private class LoadImage extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
if (imgque != null) {
imgSelectedQue.setImageDrawable(imgque);
if (getActivity() != null) {
adjustResourceEnvelope();
}
}
}
@Override
protected void onPreExecute() {
imgque = null;
imgSelectedQue.setImageDrawable(null);
imgSelectedQue.requestLayout();
}
@SuppressWarnings("deprecation")
@Override
protected Void doInBackground(Void... params) {
InputStream is;
try {
is = (InputStream) new URL(Constants.PLAYER_SERVICE_BASE_URL + "/playerservice"
+ imageurl).getContent();
imgque = Drawable.createFromStream(is, null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
imgque = null;
e.printStackTrace();
}
return null;
}
}
ここで問題となるのは、次のボタンを繰り返しクリックすると、 AsyncTaskが何度も呼び出され、すべてのURL画像がキューにあるため、ImageViewが「スライドショー」のようなすべての画像を表示することです。
最後のAsyncTask呼び出し画像のみを表示する方法はありますか?