将列表中的元素提取到数组中

时间:2016-08-26 20:03:50

标签: java android arrays function

我有一个包含访问点信息的列表wifilist: 这是我的列表适配器类:

public ListAdapterWifi(Context context, List<ScanResult> wifiList) {
        this.context = context;
        this.wifiList = wifiList;
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        return wifiList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        System.out.println("viewpos" + position);
        View view = convertView;
        if (view == null) {
            view = inflater.inflate(R.layout.listeadapter, null);
            holder = new Holder();
            holder.tvDetails = (TextView) view.findViewById(R.id.tvDetails);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.tvDetails.setText("SSID :: " + wifiList.get(position).SSID
                + "\nForce du signal reçu :: " + wifiList.get(position).level
                + "\n@ mac du point d'accès :: " + wifiList.get(position).BSSID
                + "\nCanal :: "
                + convertFrequencyToChannel(wifiList.get(position).frequency)
                + "\nFréquence :: " + wifiList.get(position).frequency
                + "\nType de sécurité :: " + wifiList.get(position).capabilities);

        return view;
    }


    public static int convertFrequencyToChannel(int freq) {
        if (freq >= 2412 && freq <= 2484) {
            return (freq - 2412) / 5 + 1;
        } else if (freq >= 5170 && freq <= 5825) {
            return (freq - 5170) / 5 + 34;
        } else {
            return -1;
        }
    }

    class Holder {
        TextView tvDetails;

    }
}

这是WifiMonitorActivity,这是在列表视图中显示列表的活动:

 public class WifiMonitorActivity extends Activity {
    private WifiManager mainWifi;
    private WifiReceiver receiverWifi;
    ListAdapterWifi adapter;
    ListView lvWifiDetails;
    List<ScanResult> wifiList;
    WifiManager wifi;



    double [] queryC = new double[3];


    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.wifiresult );
     lvWifiDetails = (ListView) findViewById(R.id.lvWifiDetails);


     mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
     receiverWifi = new WifiReceiver();
     registerReceiver(receiverWifi, new IntentFilter(
     WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
     scanWifiList();
    }
    public double [] getRSS(double [] queryC){
        if(wifilist != null){

        for (int i=0; i<wifiList.size(); i++){
        switch (wifiList.get(i).BSSID){ 
          case "56:2f:27:43:4b:f5" : queryC [0]= + wifiList.get(i).level ; break; 
          case "20:16:e8:4f:55:e8": queryC [1]  = + wifiList.get(i).level ; break; 
          case "7c:e8:d3:31:7f:b9": queryC [2] =  + wifiList.get(i).level ; break; 
        }
         }  
}

        return queryC;
        }


    private void setAdapter() {
    adapter = new ListAdapterWifi(getApplicationContext(), wifiList);
    lvWifiDetails.setAdapter(adapter);
    }
    private void scanWifiList() {
    mainWifi.startScan();
    wifiList = mainWifi.getScanResults();
    setAdapter();
    }

    class WifiReceiver extends BroadcastReceiver {
        public void onReceive(Context c, Intent intent) {


        }
    }

    }

我想用指定的SSID提取与接入点相对应的BSSID并将3 BSSID恢复到数组queryC中。然后我想像这样在我的knn类中恢复queryC:

WifiMonitorActivity w = new  WifiMonitorActivity();
        double [] query= w.getRSS(queryC);

问题是queryC没有恢复,我应该使用另一个列表而不是wifiList吗?我很困惑。

提前感谢

0 个答案:

没有答案