0

したがって、それらを正しく使用していると確信していますが、何らかの理由で最後の更新しか取得していません。

for(int i=0; i<numImages; i++)
{
    // Stuff processes here including getting a new Bitmap bmp image
    imageView.setImageBitmap(bmp);

    text.setText(text.getText()+"image "+i+" a success!\n");
    Log.d("update", text.getText()+"image "+i+" a success!\n");
}

ログ メッセージは期待どおりに表示されていますが、一連の最後のテキストの更新と最後の画像しか表示されません。何が間違っているのかわかりません

4

3 に答える 3

1

ImageView: imageView同じものを更新しているためTextView: text、最後のビットマップとテキストのみが表示されます。

すべてのビットマップとそれぞれのテキストをレイアウトに追加しようとしていますか??

次のようにします。

for(int i=0; i<numImages; i++)
{
// Stuff processes here including getting a new Bitmap bmp image
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bmp);
parent.addView(imageView);

TextView text = new TextView(this);
text.setText(text.getText()+"image "+i+" a success!\n");
parent.addView(text);
Log.d("update", text.getText()+"image "+i+" a success!\n");
}

数秒ごとにビットマップを ImageView に追加する場合:

private Timer timer = new Timer();
private TimerTask timerTask;
timerTask = new TimerTask() {
 public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
         //Keep a count and change the ImageView and Text depending on that count
        }
});   
 }
};
timer.schedule(timerTask, 0, 5000);
于 2013-04-03T05:34:32.783 に答える
0

バッファを作成してから、文字列を毎回バッファに追加する必要があります。最後にそれを表示する

StringBuffer buff = new StringBuffer();

for(int i=0; i<numImages; i++)
{
    // Stuff processes here including getting a new Bitmap bmp image
    imageView.setImageBitmap(bmp);
    buff.append (text.getText()+"image "+i+" a success!\n");
}
Log.d(buff.toString());
于 2013-04-03T05:34:52.210 に答える
0

リストビューを更新したいときに、このような問題に遭遇しました。
私のログは、いくつかの notifyDataSetChanged() が正常に実行されたことを示していますが、リストビューを変更したのは最後の呼び出しだけであり、UI 操作をブロックしたメイン スレッドに計算を入れたことがわかりました。

そのため、コードが個別のスレッドで実行されていることを確認し、メイン スレッドで UI 関連の操作のみを実行してください。新しいスレッドですべてのコードを試して text.setText(text.getText()+"image "+i+" a success!\n");、runOnUiThreadに入れることができます

于 2013-04-03T06:39:37.677 に答える