Show Result of an onResultScan in a Recycleview

Asked

Viewed 30 times

0

I’m riding a APP for the course, it’s about Wi-Fi, precise list the search for Wi-Fi available and put on Recycleview, in the example I’ll show him listing in a Listview, and in the Recycleview I can’t do it because I can’t get the result of onResultScan and and play for the Recycle(BEGINNER)

Class Mainactivity

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;
    }
}
  • You know how to implement using a Listview but you don’t know how to implement using a Recycleview, that’s it?

  • That’s because in recicle I don’t know how to pass the result to the Adapter, that’s the truth.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.