首页 > 解决方案 > 扫描我周围的蓝牙设备时,Listview 显示空行

问题描述

我制作了蓝牙扫描仪应用程序,它扫描我周围的设备并将其显示在列表视图中。它为我显示蓝牙设备,在 Listview 中有很多空行。它只能扫描名称以“*”开头的设备。有人可以指导我删除这些空行吗?

      private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.i("Action",action);

        if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            statusTextView.setText("Finished");
            searchButton.setEnabled(true);
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            String name = device.getName();
            String address = device.getAddress();
            String rssi = Integer.toString(intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE));
            //Log.i("Device Found","Name: " + name + " Address: " + address + " RSSI: " + rssi);

            if (!addresses.contains(address)) {
                addresses.add(address);
                String deviceString = "";
                if(name == null || name.equals("") ) {
                   // listView.setVisibility(View.GONE);
                    System.out.println("Name is null");
                    } else if(name.charAt(0) == "*".charAt(0)){
                     deviceString = name + " - RSSI " + rssi + "dBm";
                }
                bluetoothDevices.add(deviceString);
                arrayAdapter.notifyDataSetChanged();
            }
        }
    }
};

标签: javaandroid

解决方案


推荐阅读