您可以使用ListView来显示设备列表。以下是一个示例代码:

  1. 在布局文件(例如activity_main.xml)中添加ListView组件:
<ListView
    android:id="@+id/deviceListView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. 在活动中,找到ListView并将设备列表适配器设置为ListView的适配器:
ListView deviceListView = findViewById(R.id.deviceListView);
List<String> deviceList = findDevices(); // 用于获取设备列表的方法,返回一个字符串列表
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, deviceList);
deviceListView.setAdapter(adapter);

在上述代码中,findDevices()是一个自定义的方法,用于获取设备列表并返回一个字符串列表。您可以根据您的需求自定义此方法。

  1. 最后,确保你的设备列表在适配器中更新时,调用adapter.notifyDataSetChanged(),以便在列表中显示新的设备。

请注意,上述代码仅提供了一个基本的示例,您可以根据自己的需求进行修改和扩展

将找到的 设备遍历在list view 中

原文地址: https://www.cveoy.top/t/topic/hDDG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录