问题
Thanks in advance.
I m working in game application using accelerometer. but i've facing a problem, when i update textview in "onSensorChange" method of accelerometer.application not perform good.
My code like this.
int nCounter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTV_CountTextView = (Textview)findViewById(R.id.TextView);
}
.... ......
public void onSensorChanged(SensorEvent sensorEvent) {
{
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) {
// Set sensor values as acceleration
yAcceleration = sensorEvent.values[1];
xAcceleration = sensorEvent.values[2];
nCounter++;
mTV_CountTextView.settext(""+nCounter);
}
}
}
回答1:
try this one..
mTV_CountTextView.settext(""+String.valueOf(nCounter));
may be your are using Integer for settext so you are getting error..
回答2:
setText() instead of settext ?
You're polling the Orientation sensor's values to look at the device acceleration o_O ?
来源:https://stackoverflow.com/questions/10911459/how-to-set-text-in-onsensorchange-metod-accelerometer