private ListView localListView=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//生成传感器管理实例
List<Sensor> sensorList=sm.getSensorList(Sensor.TYPE_ALL);//获取系统所有支持的传感器
MyListAdapter adapter=new MyListAdapter(this ,sensorList);//构造自定义数据桥接类
localListView=new ListView(this);//新创建一个列表控件
localListView.setAdapter(adapter);//将自定义的数据桥接类连接绑定到列表
setContentView(localListView);//设定界面布局为当前的列表
}
--------------------手机上显示出来------------------------------
public class MyListAdapter extends BaseAdapter {
List<Sensor> sensorListV=null;
Context context;
public MyListAdapter(Context context,List<Sensor>sensorListV){
this.context=context;
this.sensorListV=sensorListV;
}
/**
* 返回 Sensor 类型
* @param sensorType
* @return
*/
private String getSensorNameByType(int sensorType){
String name="";
switch(sensorType){
case Sensor.TYPE_ACCELEROMETER:
name="加速器";
break;
case Sensor.TYPE_GYROSCOPE:
name="陀螺仪";
break;
case Sensor.TYPE_LIGHT:
name="光照";
break;
case Sensor.TYPE_MAGNETIC_FIELD:
name="磁力计";
break;
case Sensor.TYPE_ORIENTATION:
name="方位传感器";
break;
case Sensor.TYPE_PROXIMITY:
name="距离传感器";
break;
case Sensor.TYPE_TEMPERATURE:
name="温度传感器";
break;
case Sensor.TYPE_PRESSURE:
name="压力传感器";
break;
}
return name;
}
public int getCount() {
// TODO Auto-generated method stub
return sensorListV.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return sensorListV.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(sensorListV!=null){
View itemView=LinearLayout.inflate(context,R.layout.sensor_list, null);
//通过资源文件 ID,生成一个 View
Sensor sensor=sensorListV.get(position);
((TextView)itemView.findViewById(R.id.sensor_type)).setText("类型:"+sensor.getType());
((TextView)itemView.findViewById(R.id.sensor_version)).setText(" 版 本 :"+sensor.
getVersion());
((TextView)itemView.findViewById(R.id.sensor_name)).setText(""+getSensorNameByType(sensor.getType()));
((TextView)itemView.findViewById(R.id.sensor_max_range)).setText("最大值:"+sensor.
getMaximumRange());
((TextView)itemView.findViewById(R.id.sensor_power)).setText(" 功 率 :"+sensor.
getPower());
((TextView)itemView.findViewById(R.id.sensor_resolution)).setText("精度:"+sensor.
getResolution());
((TextView)itemView.findViewById(R.id.sensor_vendor)).setText(" 供 应 商 :"+sensor.
getVendor());
return itemView;
}
else{
return null;
}
}
}
走在前面的人有饭吃,走在后面的人没饭吃,技术先人一步,你就是赢家,欢迎到未来新技术手机操作系统firefox os 5狐论坛网"www.5fox.cn"