为了账号安全,请及时绑定邮箱和手机立即绑定

如何将Android Wifi扫描结果放入列表?

如何将Android Wifi扫描结果放入列表?

守候你守候我 2019-08-31 11:08:48
我知道如何获得<List>Android Wifi扫描,但我无法找出制作列表适配器的最佳方法。我想将SSID和BSSID从<List>扫描绑定到text1和text2。我一直在做的样本wifi.startScan();        // get list of the results in object format ( like an array )        List<ScanResult> results = wifi.getScanResults();`        // loop that goes through list        for (ScanResult result : results) {            Toast.makeText(this, result.SSID + " " + result.level,                    Toast.LENGTH_SHORT).show();和:private void fillDataFromDb() {        Cursor scanCursor = Db.fetchAllScans();        startManagingCursor(scanCursor);`        // Create an array to specify the fields we want to display in the list        // (only TITLE)        String[] from = new String[] { WifiDbAdapter.KEY_BSSID,                WifiDbAdapter.KEY_SSID };        // and an array of the fields we want to bind those fields to (in this        // case just text1)        int[] to = new int[] { R.id.text1, R.id.text2 };        // Now create a simple cursor adapter and set it to display        SimpleCursorAdapter scansdb = new SimpleCursorAdapter(this,                R.layout.scan_row, scanCursor, from, to);        setListAdapter(scansdb);    }
查看完整描述

3 回答

?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

除了接受的答案,您还需要在AndroidManifest中使用以下权限才能使其正常工作:


 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 


查看完整回答
反对 回复 2019-08-31
  • 3 回答
  • 0 关注
  • 776 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信