How to set text in onSensorChange metod +accelerometer

为君一笑 提交于 2019-12-25 18:56:05

问题


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:


  1. setText() instead of settext ?

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!