im trying to get 100 accelerometer readings in 1 second, but instead of 100 different readings, it gives me 1 same reading 100 times.
I'm trying to display these 100 accelerometer readings when i press a button in my app
my MainActivity has this variable named
float ax;
which is where the accelerometer reading (of x axis) is continuously stored.
and i have this button code in my OnCreate() method
button = (Button)findViewById(R.id.startbutton); //inits button
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
BuildTable();
}
});
which triggers the BuildTable() function (which is displays the output on the app itself)
my BuildTable() has something like this
public void BuildTable()
{
TableRow trow = new TableRow(this);
TextView text = new TextView(this);
int count = 0;
while (count < 100)
{
if(System.currentTimeMillis() - lasttime >= 10)
{
lasttime = System.currentTimeMillis();
text = new TextView(this);
Log.d("MyApp","ax is: "+ax);
text.setText(""+ax);
trow = new TableRow(this);
trow.addView(text);
table.addView(trow,count);
count++;
}
}
}
and the OnSensorChanged() function looks like this
@Override
public void onSensorChanged(SensorEvent event) {
ax = event.values[0];
}
which just updates ax.
How does the button click pause the updating of ax? how do i fix this?
Cheers