ボタンを押した後、一度に 5 秒間隔で TextView を更新しようとしていますが、アプリケーションを実行すると、TextView は実行中のループの最後の値のみを表示します。
ここに私がしようとしているものがあります:
private Runnable textUpdate = new Runnable() {
public void run() {
textOutput = (TextView)findViewById(R.id.textOutput);
textOutput.setText("Reading Number " + (rIndex+1) + "\n");
textOutput.append(sensorTime[rIndex] + "\n");
textOutput.append("Value: " + rPoint.getValue() + "\n");
}
};
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHandler = new Handler();
TextView textOutput = (TextView) findViewById(R.id.textOutput);
textOutput.setText("Simulation output:\n");
Button button03 = (Button) findViewById(R.id.button03);
button03.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i < index; i++) {
rIndex = i;
rPoint = dp[i];
mHandler.postDelayed(textUpdate, 5000);
}
}
});
}
出力しようとしている情報の最後の値だけが TextView に表示されている理由がわかりません。
どんな助けでも大歓迎です。