Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在布局中创建的listview中列出配对的蓝牙设备_Android_Xcode_Bluetooth_Helpers_Core Bluetooth - Fatal编程技术网

Android 在布局中创建的listview中列出配对的蓝牙设备

Android 在布局中创建的listview中列出配对的蓝牙设备,android,xcode,bluetooth,helpers,core-bluetooth,Android,Xcode,Bluetooth,Helpers,Core Bluetooth,我想在布局中创建的列表中列出所有配对设备。。这个代码有什么错误?我刚刚创建了这个函数来显示所有绑定的设备 void tooth_scan() { ListView listView = (ListView) findViewById(R.id.pairList); Set<BluetoothDevice> pairedDevices = bAdapter.getBondedDevices(); devicesPaired = new String[paired

我想在布局中创建的列表中列出所有配对设备。。这个代码有什么错误?我刚刚创建了这个函数来显示所有绑定的设备

void tooth_scan() {
    ListView listView = (ListView) findViewById(R.id.pairList);
    Set<BluetoothDevice> pairedDevices = bAdapter.getBondedDevices();
    devicesPaired = new String[pairedDevices.size()];
    int count = 0;
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            devicesPaired[count] = device.getName();
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1,
                devicesPaired);
        listView.setAdapter(adapter);
    }
}
void tooth_scan(){
ListView ListView=(ListView)findViewById(R.id.pairList);
Set pairedDevices=bAdapter.getBondedDevices();
devicesPaired=新字符串[pairedDevices.size()];
整数计数=0;
如果(pairedDevices.size()>0){
用于(蓝牙设备:pairedDevices){
devicesPaired[count]=device.getName();
}
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,android.R.id.text1,
设备配对);
setAdapter(适配器);
}
}
public void showPairedDevices()
{
设置pairedDevices=mBluetoothAdapter.getBondedDevices();
如果(pairedDevices.size()>0){
ArrayList bluetoothDevices=新的ArrayList();
用于(蓝牙设备:pairedDevices){
字符串deviceName=device.getName();//获取BT名称
字符串deviceAddress=device.getAddress();//获取MAC
ListView ListView=(ListView)findViewById(R.id.paired_list);
bluetoothDevices.add(deviceName);
最终ArrayAdapter=新的ArrayAdapter(MainActivity.this,android.R.layout.simple\u list\u item\u 1,蓝牙设备);
setAdapter(适配器);
}
}
}

您是否收到任何异常或未显示任何条目?@waqas-no如果我调用此函数,则应用程序将停止工作并发出错误消息当您的应用程序失败时,它将在logcat中生成一些信息,在这里发布那些日志我已经修改了代码如何注释它?我在日志中得到了这些信息确保你使用Set,因为你需要得到不同的设备,否则你会得到重复的列表。祝你一切顺利
public void showPairedDevices()
    {
        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        if (pairedDevices.size() > 0) {
            ArrayList<String> bluetoothDevices = new ArrayList<String>();
            for (BluetoothDevice device : pairedDevices) {

                String deviceName = device.getName(); // Get BT name
                String deviceAddress = device.getAddress(); // Get MAC
                ListView listView = (ListView)findViewById(R.id.paired_list);

                bluetoothDevices.add(deviceName);

                final ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,bluetoothDevices);
                listView.setAdapter(adapter);

            }

        }
    }