我有这个代码:
public class Chronom extends Activity
{
Chronometer mChronometer;
ProgressBar progre;
int total=1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//layout
setContentView(R.layout.main7watingscreen);
//Start Chronometer
mChronometer = (Chronometer) findViewById(R.id.chrono1);
mChronometer.start();
progre = (ProgressBar) findViewById(R.id.progressBar1);
MyCount counter = new MyCount(31000,300);
counter.start();
}
public class MyCount extends CountDownTimer
{
public MyCount(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish()
{
Intent myIntent = new Intent( Chronom.this, MainMenu.class);
startActivityForResult(myIntent, 0);
}
@Override
public void onTick(long millisUntilFinished)
{
total++;
progre.setProgress(total);
}
}
我想将加速度计值(x、y 和 z)存储在一个矢量中(可以是其他形式,我想知道您的意见)。
但我想在进度条充满的同时执行此操作(它在 30 秒后停止)。比如在 1 秒开始存储并在 30 秒后停止。
如果你不明白我的问题,请说出来,我会更好地解释。
怎么做?请帮忙!
最佳答案
通过 onSensorChanged()
回调(参见 SensorListener 引用),您每次更改传感器值时都可以获取它们。 您无法在设定的时间查询传感器数据。
有一种解决方法:让监听器在每次更改时保存值(即在 onSensorChanged()
方法中),并查询这些保存的值使用你的计时器。例如,您可以为其使用 static float[]
数组或 SharedPreferences
值。
关于android - 如何存储加速度计值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391512/