【发布时间】:2011-07-24 02:26:42
【问题描述】:
我知道如何获得<List> 的 Android Wifi 扫描,但我想不出用它们制作列表适配器的最佳方法。我只想将扫描的<List> 中的 SSID 和 BSSID 绑定到 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);
}
【问题讨论】:
-
我想看看你也有一些代码。你得到这样的结果了吗?: List
results = wifi.getScanResults(); -
我已经这样做了,只是为了获取 toast 消息:
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(); -
@eternalmatt 是的,这正是我获得结果的方式,而且效果很好,只是不知道如何将其绑定到列表视图
标签: java android listview android-wifi