【问】android的界面闪一下就消失了~~~

catsight catsight 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面是我的代码,是一个简单的关于传感器模拟器的程序,拜托了,纠结死我了~~~~

package com.tyut;

import org.openintents.sensorsimulator.hardware.Sensor;
import org.openintents.sensorsimulator.hardware.SensorEvent;
import org.openintents.sensorsimulator.hardware.SensorEventListener;
import org.openintents.sensorsimulator.hardware.SensorManagerSimulator;

import android.app.Activity;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class Test extends Activity {

// SensorManager mySensorManager; //SensorManager对象引用 =》对真机操作使用的对象
SensorManagerSimulator mySensorManager;//使用SensorSimulator模拟时声明SensorManager对象引用的方法

private TextView jsd_x; //TextView对象的引用
private TextView jsd_y; //TextView对象的引用
private TextView jsd_z; //TextView对象的引用

private SensorEventListener mySensorListener = new SensorEventListener(){

public void onAccuracyChanged(Sensor arg0, int arg1) {
}

public void onSensorChanged(SensorEvent event) {
if(event.sensor ==
mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
){ //判断是否为加速度传感器变化产生的数据
jsd_x.setText("X轴方向的加速度:"+event.values[0]);//将提取的数据显示到TextView
jsd_y.setText("y轴方向上的加速度:"+event.values[1]);//将提取的数据显示到TextView
jsd_z.setText("z轴方向上的加速度: "+event.values[2]);//将提取的数据显示到TextView
}
}
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

jsd_x = (TextView) findViewById(R.id.jsd_x); //获取屏幕上 TextView控件的引用
jsd_y = (TextView) findViewById(R.id.jsd_y); //获得屏幕上TextView控件的引用
jsd_z = (TextView) findViewById(R.id.jsd_z); //获得屏幕上TextView控件的引用

mySensorManager =
SensorManagerSimulator.getSystemService(this,SENSOR_SERVICE);
mySensorManager.connectSimulator();
}


@Override
protected void onResume() { //重写onResume()方法

mySensorManager.registerListener(
mySensorListener,
mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_FASTEST
);
super.onResume();
}


@Override
protected void onPause() { //重写onPause() 方法

mySensorManager.unregisterListener(mySensorListener); //取消注册监听器
super.onPause();
}
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
catsight
Eclipse 58,440 成员 49,457 内容