将加速度计数据推入数组 [英] Pushing accelerometer data into an array
本文介绍了将加速度计数据推入数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在阵列中记录来自加速度计的 Z 轴数据.
I'm having trouble recording the Z-axis data from the accelerometer in an array.
我想我可能在一些基本的 Java 规则上失败了,但这是我想要做的:
I think I'm probably failing on some basic java rules, but here's what I'm trying to do:
private ArrayList<Float[]> z = new ArrayList<Float[]>();
protected void onCreate(Bundle savedInstanceState) {
SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor accelerometer = manager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
z.add(event.values[2]);
}
但是每当我尝试添加到数组列表时,我都会得到:
But whenever I try to add to the arraylist I get:
ArrayList 类型中的 add(Float[]) 方法不适用于参数 (float)"
"The method add(Float[]) in the type ArrayList is not applicable for the arguments (float)"
如何将 z 轴数据添加到数组中?
How can I add the z axis data to an array?
推荐答案
这是因为你的Float[]
类型的ArrayList
.
替换以下内容
private ArrayList<Float[]> z = new ArrayList<Float[]>();
与
ArrayList<Float> z = new ArrayList<Float>();
这篇关于将加速度计数据推入数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文