0

我在计时器中刷新图表。当函数刷新图表时,只有一切正常,但是当我将代码添加到 USB 通信时,图表仅在函数完成时更新(一次)。

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
    for (int i = 0; i < data[0].length; i++) {
        data[0][i] = getRandom(0, 20);
        data[1][i] = (i + 1);
    }

    lineGraph.refreshChart(data[0], data[1]);
    if (complete[0]) {
        timer.cancel();
        timer.purge();
        return;
    }

    }
}, 100, 100);

// without the following two lines works fine
usbPacketTransfer.send();
recivedData = usbPacketTransfer.recive();
4

1 回答 1

0

您需要将所有网络操作移出主 UI 线程。我建议使用AsyncTaskorThread来执行此操作。您的网络命令正在阻止其他一切运行,这就是为什么它只在最后更新。

于 2012-06-28T21:42:19.867 回答