0

プログレスバーを使用して多くのimageViewでインターネットから多くの画像を読み込もうとしています。成功しましたが、すべての画像が最初のimageViewに(スライダーとして)読み込まれますが、それを正しくする方法がわかりません各画像を 1 つの imageView にダウンロードすることを意味します。

4

3 に答える 3

1

DownloaderAsyncTasks コンストラクターにパラメーターを追加します。で使用します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);
}

新しいコンストラクターで asynctasks の初期化を変更します。

for(int i = 0; i < 5; i++) {
    DownloaderAsyncTask asyncTask = new DownloaderAsyncTask(getApplicationContext(), i);
    asyncTask.execute(links[i]);
}

また、progCounter 値を取得するときに、resultCounter タグに変更します。

// 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);
}
于 2013-10-26T17:39:17.030 に答える
1

このようなプロジェクトに取り組んでいました。この遅延ローダーを使用して成功しました。

于 2013-10-26T19:30:59.550 に答える
0

これはあなたの間違いです

あなたのBroadcastReceiver receiveImageで

インテントからprogCounterの値を取得しようとしています。

  int progCounter = intent.getIntExtra("resultCounter", 0);

しかし、非同期タスクでは、resultCounterの意図を送信していないため、意図がないため、意図の値を取得しようとするたびに0 ("resultCounter", 0)が返されます。

于 2013-10-26T17:29:44.880 に答える