当使用BluetoothDevice类型的ArrayList作为最后一个参数传递适配器时,在ListView中显示蓝牙名称而不是MAC地址

时间:2013-05-10 15:05:11

标签: android android-listview bluetooth

以下代码显示了listview中找到的每个蓝牙的MAC地址,因为我传递的是BluetoothDevice类型的ArrayList。我知道我可以使用BlueToothDevice.EXTRA_NAME获取每个蓝牙设备的名称,然后将它们全部放入String类型的ArrayList中,然后传递此ArrayList以获得我想要的内容。但是,我无法做到这一点,因为BluetoothDevice类型的ArrayList是用户点击它时需要连接的那些设备(具有MAC地址)。这样我可以连接到每个蓝牙设备,但在列表视图中只显示每个蓝牙设备的MAC地址。如何使其显示蓝牙的名称而不是其MAC地址,仍然能够连接。谢谢。

private ArrayList<BluetoothDevice> deviceList = new ArrayList<BluetoothDevice>();

ArrayAdapter adapter = new ArrayAdapter<BluetoothDevice>(this, android.R.layout.simple_list_item_1, deviceList);

btListView.setAdapter(adapter);

0 个答案:

没有答案