java - 扫描我周围的蓝牙设备时,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();
}
}
}
};
解决方案
推荐阅读
- python - 在 Pandas 数据框中,如何提取同一列中不同行的值之间的差异,以第二列为条件?
- sql - 已分配最大员工人数的项目
- javascript - 动画元素的意外行为
- java - 如何在 selenium web 驱动程序中使用键盘键 (ctrl-f) 打开网页上的搜索框
- ruby-on-rails - 路由错误未初始化常量 ArticleController rails app
- java - 找出负数和正数之间的差异
- reactjs - 反应组件未在路线上呈现更改
- python - “->”在“矩形(表面,颜色,矩形,宽度=0)->矩形”中是什么意思
- jenkins - 在 Jenkins 多分支项目中使用 msbuild
- java - 找不到 JRI 本机库。请确保 JRI 本机库位于 java.library.path 中列出的目录中