I'm trying to populate a ListView
with the List returned by the getScanResults()
method of the WifiManager
class. However, I would not want to have to go through this list, after all, all the information I need is already in it. However, by passing this list directly to this method, it displays all properties of the ScanResult
class for each item. I would like to be able to display only the SSID.
package tk.joaoeduardo.metropolitano;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Main extends Activity {
private ListView list;
private WifiManager wifi;
private ArrayAdapter<ScanResult> adapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
protected void onStart() {
super.onStart();
list = (ListView) findViewById(R.id.list);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
adapter = new ArrayAdapter<ScanResult>(this, android.R.layout.simple_list_item_1);
}
protected void onResume() {
super.onResume();
adapter.addAll(wifi.getScanResults());
list.setAdapter(adapter);
}
protected void onPause() {
super.onPause();
list = null;
wifi = null;
adapter = null;
}
}