2013-10-25 52 views
0

是否可能只显示sensor namevendor这个?传感器名称和供应商Android

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, 
      android.R.layout.simple_list_item_1, deviceSensors)); 
} 
} 

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

回答

0

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

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

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

+0

我认为这是可能只提取我需要从这个代码:-( –

+0

@David_D:AFAIK,不,让我们拭目以待,看看是否有其他解决方案 – kosa

+0

我希望ahaha。因为你的解决方案可能是一个对我来说太多了:) –