Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
174 views
Welcome To Ask or Share your Answers For Others

1 Answer

try this one..

mTV_CountTextView.settext(""+String.valueOf(nCounter));

may be your are using Integer for settext so you are getting error..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...