I am putting an APP for the course, it is about Wi-Fi , I need to list available Wi-Fi in the Recycleview , in the example I'm going to show it's listing in a ListView , and Recycleview I can not do because I can not get the result onResultScan and play for recycle
MainActivity class
public class MainActivity extends Activity implements OnClickListener, Wifi.WiFiListener, AdapterView.OnItemClickListener {
private Wifi wiFi;
private ListView list;
private ArrayAdapter<String> adapter;
private ArrayList<String> itens;
private List<ScanResult> scans;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.botao).setOnClickListener(this);
list = (ListView) findViewById(R.id.list);
itens = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this,R.layout.list_item, itens);
// adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, itens);
list.setAdapter(adapter);
}
public void onClick(View view) {
Toast.makeText(this, "Buscando....", Toast.LENGTH_LONG).show();
wiFi = Wifi.startScanWIFI(this, this);
}
public void onResultScan(Context arg0, Intent arg1, List<ScanResult> results) {
scans = results;
itens.clear();
for (ScanResult scanResult : results) {
itens.add(scanResult.SSID /*+ " - " + scanResult.BSSID*/);
}
adapter.notifyDataSetChanged();
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//Configuro uma rede baseada nos dados encontrados.
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.BSSID = scans.get(arg2).BSSID;
wifiConfiguration.SSID = "\"" + scans.get(arg2).SSID + "\"";
wifiConfiguration.preSharedKey = "\"mpt211992manaus\"";
//Conecto na nova rede criada.
WifiManager wifiManager = wiFi.getWifiManager(this);
int netId = wifiManager.addNetwork(wifiConfiguration);
wifiManager.saveConfiguration();
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
}
}
Class Adapter_Wifi
public class Adapter_Wifi extends RecyclerView.Adapter{
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
}