title: How to connect to a Wifi ScanResult item
body: <p>i'm trying to create a custom WifiSettings.</p>
  
  <p>I create an activity:</p>
  
  <pre><code>package manual;    
  import java.util.ArrayList;
  import java.util.HashMap;    
  import java.util.List;    
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.Context;    
  import android.content.Intent;     
  import android.content.IntentFilter;    
  import android.net.wifi.ScanResult;    
  import android.net.wifi.WifiConfiguration;   
  import android.net.wifi.WifiManager;    
  import android.os.Bundle;    
  import android.util.Log;   
  import android.view.View;    
  import android.view.View.OnClickListener;    
  import android.widget.AdapterView;    
  import android.widget.Button;    
  import android.widget.CompoundButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  import android.widget.ImageButton;
  import android.widget.ListView;    
  import android.widget.SimpleAdapter;    
  import android.widget.Switch;
  import android.widget.TextView;    
  import android.widget.Toast;
  
  public class WiFiDemo extends Activity implements OnClickListener
   {      
      WifiManager wifi;       
      ListView lv;
      TextView textStatus;
      Button buttonScan;
      Switch enable;
      int size = 0;
      List&lt;ScanResult&gt; results;
  
      String ITEM_KEY = "key";
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      SimpleAdapter adapter;
  
      /* Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.wifi);
          buttonScan = (Button) findViewById(R.id.updateWifi);
          buttonScan.setOnClickListener(this);
          enable     = (Switch) findViewById(R.id.switch1);
          lv = (ListView)findViewById(R.id.listView1);
  
          wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
          enable.setChecked(wifi.isWifiEnabled());
          enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
                  wifi.setWifiEnabled(flag);
                  if(flag){
                      arraylist.clear();
                      lv.setVisibility(View.VISIBLE);
                      buttonScan.setEnabled(true);
                      wifi.startScan();
                  }else{
                      lv.setVisibility(View.INVISIBLE);
                      buttonScan.setEnabled(false);
                  }
              }
          });
          this.adapter = new SimpleAdapter(WiFiDemo.this, arraylist, R.layout.wifi_item, new String[] { ITEM_KEY }, new int[] { R.id.list_value });
          lv.setAdapter(this.adapter);
          lv.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  int a = lv.getSelectedItemPosition();
  
              }
          });
  
          registerReceiver(new BroadcastReceiver()
          {
              @Override
              public void onReceive(Context c, Intent intent) 
              {
                 results = wifi.getScanResults();
                 size = results.size();
                 for(int i=size-1;i&gt;=0;i--){
                     HashMap&lt;String, String&gt; item = new HashMap&lt;String, String&gt;();                       
                     item.put(ITEM_KEY, results.get(i).SSID);
                     arraylist.add(item);
                 }
                 if(size&gt;0)
                     adapter.notifyDataSetChanged();
              }
          }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));                    
      }
  
      public void onClick(View view) 
      {
          arraylist.clear();          
          wifi.startScan();
          Toast.makeText(this, "Scanning....", Toast.LENGTH_SHORT).show();
  
      }    
  }
  </code></pre>
  
  <p>When an user clicks on an item of ListView, it needs to connect to that wifi so</p>
  
  <pre><code>lv.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          int a = lv.getSelectedItemPosition();
          ScanResult wifiChoosed = results.get(a);            
          //WHAT I NEED TO DO HERE? 
      }
  });
  </code></pre>
  
  <p>What i need to do with <code>ScanResult wifiChoosed = results.get(a);</code> to connect to wifi?</p>