2
我正在通過可用範圍內的Bluetooth devices
進行搜索。出於某種原因,每個找到的設備將被添加到ListView 兩次,當它只應顯示一次。藍牙添加到ListView兩次而不是一次
有沒有人有任何想法我在做什麼錯在這裏?代碼如下。
當發現找到的設備
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device;
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
Log.v("test", "test");
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
// When discovery is finished, change the Activity title
setProgressBarIndeterminateVisibility(false);
setTitle(R.string.select_device);
if (mNewDevicesArrayAdapter.getCount() == 0) {
String noDevices = getResources().getText(R.string.none_found).toString();
mNewDevicesArrayAdapter.add(noDevices);
}
}
然後它又添加了兩次,而不是一個...我檢查兩種方式,但得到相同的結果.... !!! == ==我應用!=這個,但沒有得到相同的結果...和感謝您的答覆 – RobinHood 2011-05-30 07:10:23