android listview控件在ui上显示蓝牙设备

问题遇到的现象和发生背景

我目前在做android项目 :搜索蓝牙设备并通过列表显示 我用的是listview 使用的广播接收然后用listview的adapter 去添加设备信息 但是显示不出来

用代码块功能插入代码,请勿粘贴截图

private final BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
@SuppressLint("MissingPermission")
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG,"有回调");
switch (action) {
case BluetoothDevice.ACTION_FOUND:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
//已经匹配的设备
String str = device.getName() + "\n" + device.getAddress();
int deviceTypeImg = BtUtil.getDeviceType(device.getBluetoothClass( ) );
Log.d(TAG, "列表:" + str + " 图片:" + Long.toHexString(deviceTypeImg) );
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
Log.d(TAG, "有匹配到设备");
bluetoothlist.add(new SPPView(deviceTypeImg, (str + "(已配对)") ) );
} else if (!bluetoothlist.contains(str)) {
Log.d(TAG, "有未匹配的设备");
bluetoothlist.add(new SPPView(deviceTypeImg, (str + "(未配对)") ) );
}
break;
case BluetoothAdapter.ACTION_DISCOVERY_STARTED:
Log.d(TAG, "开始搜索的设备");
Toast.makeText(ScanSppFragment.this, "开始搜索", Toast.LENGTH_SHORT).show();
break;
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
Log.d(TAG, "搜索完毕");
Toast.makeText(ScanSppFragment.this, "搜索完毕", Toast.LENGTH_SHORT).show();
break;
}
mAdapter = new SPPAdapter(context,bluetoothlist);
listView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
};

运行结果及报错内容

没有报错

我想要达到的结果

显示出来

不是这样玩的,activity启动就先把适配器new好。然后在你的搜索蓝牙成功后去把list传给适配器,然后刷新列表即可。(确认你的数据正常,然后数据是否传给适配器并设置到相应的列表中去了,适配器中有个getcount方法,这个方法里面需要给int值,这个就是你列表数据的长度。)

也没看到你的运行结果呀,Log打印出来有匹配到数据吗

debug 代码,单步调试。