有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java传感器名称和供应商Android

是否可以仅显示来自此的sensor namevendor

public class SensorikTestActivity extends Activity {

private ListView listView;
private SensorManager mSensorManager;
private List<Sensor> deviceSensors = null;

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

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
    listView.setAdapter(new ArrayAdapter<Sensor>(this,
            安卓.R.layout.simple_list_item_1, deviceSensors));
}
}

实际上它显示了传感器的所有信息,但我只需要一些信息。谢谢


共 (1) 个答案

  1. # 1 楼答案

    没有内置的方法。你需要做一些编码

    创建像SensorDetails这样的自定义对象,只使用您想要的属性(名称、供应商等)

    而不是List<Sensor> deviceSensors创建List<YourCustomClass>。使用Sensor列表中的值填充自定义对象,并将其设置为Adapter