0

更新:

现在像魅力一样运行。在 Alex Klimashevsky 的帮助下,他为我指明了正确的方向。基本上我将 for 循环网格化了。这应该是:

for(int a = 1; a < x.length; a++) {
    y[(a)]=yprev[a-1];
}
y[0]=value_i/10;

for(int a = 0; a < x.length; a++) {
    yprev[a]=y[a];
}

谢谢!

也许有人可以告诉我出了什么问题:这是一个非常基本的绘图程序,但现在已经足够好了。

我在视图类的顶部声明了这一点:

private int[] x = {50, 60, 70, 80, 90, 100, 110,120,130};
private int[] y= {500,500,500,500,500,500,500,500,500};
private int[] yprev={500,500,500,500,100,500,500,500,500};

我把它放在 onDraw 中:

for(int a =  (x.length-1); a ==0; a--) {
    y[(a+1)]=yprev[i]; //Shift everything one place to the right
}
y[0]=value/10; //Fill in the newest value for temperature on the first index

for(int a =  (x.length); a ==0; a--) {
    yprev[a]=y[a]; //Store the latest array, such it can be re-used in the next cycle**
}

paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(Color.RED);

Path path = new Path();
path.moveTo(x[0], y[0]);
for(int b = 1; b < x.length; b++) {
    path.lineTo(x[b], y[b]);
}
canvas.drawPath(path, paint);

绘图工作,但不知何故它不会改变我的情节。新值每次都绘制在第一个索引上,所有其他值保持 500。有什么想法吗?

最好的问候,凯文

4

1 回答 1

0

首先看得到这个:

for(int a =  (x.length-1); a >=0; a--) {
    y[(a+1)]=yprev[i]; //Shift everything one place to the right
}
y[0]=value/10; //Fill in the newest value for temperature on the first index

for(int a =  (x.length); a >=0; a--) {
    yprev[a]=y[a]; //Store the latest array, such it can be re-used in the next cycle**
}

在您的代码中,此循环不起作用

于 2012-04-16T17:11:19.793 回答