java - Android Studio:listview 没有显示 Wifi p2p
问题描述
我正在编写用于发现 Wifi 并显示列表的代码。如果无法检测到 wifi,则敬酒“无设备”。但是,列表和吐司都没有出现。有什么问题吗?
我的代码是:
public void onPeersAvailable(WifiP2pDeviceList peerList) {
if (!peerList.getDeviceList().equals(peers)){
peers.clear();
peers.addAll(peerList.getDeviceList());
deviceNameArray=new String[peerList.getDeviceList().size()];
deviceArray=new WifiP2pDevice[peerList.getDeviceList().size()];
int index = 0;
for(WifiP2pDevice device : peerList.getDeviceList()){
deviceNameArray[index] = device.deviceName;
deviceArray[index] = device;
index++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,deviceNameArray);
listView.setAdapter(adapter);
}
if (peers.size()==0){
Toast.makeText(getApplicationContext(),"No Device", Toast.LENGTH_SHORT).show();
return;
}
}
解决方案
推荐阅读
- java - 无法在基本 JEE8 登录应用程序中注入 javax.security.enterprise.SecurityContext
- multithreading - 使用 awscli 的 aws s3 cp 命令传输大文件的最佳方法是什么
- python - 是否可以在没有循环的有序事件序列中选择正确的行?
- class - 如何创建 CheckBoxTile ListView?
- c# - 使用 await client.GetAsync 来自 Xamarin.Forms ViewModel 的未经授权的 401 错误
- php - 如何仅将 Laravel Blade 表视图中的特定列导出到 Ecxel 文件?
- asp.net - 谷歌云 SQL Server 从本地主机连接,但不是从 Godaddy Windows 托管 ASP.Net
- html - 为什么我的 ngFor 显示在一行中只显示我的行和类别的一项
- mysql - MySQL 仅在记录的时间戳超过 5 分钟时插入
- orchardcms - 如何在 OrchardCoreCMS 中向 Content-Type 添加字段?