After trying several things with no success, I decided to approach a different method. I am still unable to display my Array of Strings on my listview, I've been very careful about my code and I've read all the tutorials (I think) that are available to me in this website. Here is a more detailed explanation of what I am trying to do, and my new approach:
My GOAL: To be able to copy the SSID names of my remembered networks on my phone., and then print them in a simple ListView.
My Steps:
1. Accessing the Android WIFIManager
2. Copying the name of the SSIDs to an ArrayList of Strings.
3. Creating an ArrayAdapter to connect the ArrayList of Strings to the ListView.
4. Displaying ListView
Here is my Java code:
Using java Syntax Highlighting
- Java:
- package com.android.wifi.manager;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ListActivity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- 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.OnClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.content.DialogInterface;
- public class Main extends Activity {
- List<WifiConfiguration> remembered;
- WifiManager wifi;
- ListView mylistview = (ListView)findViewById(R.id.list_view);
- int count=0;
- int i=0;
- int k=0;
- int idx=0;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // Create the ArrayList of Strings
- ArrayList<String> mStrings = new ArrayList<String>();
- // Create and link the ArrayAdapter to the ArrayList of Strings
- ArrayAdapter<String> aa;
- aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
- mStrings);
- mylistview.setAdapter(aa);
- // Access to the WiFiManager API and initializes it.
- wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
- // Access to the currently configured networks stored on your device.
- remembered = wifi.getConfiguredNetworks();
- // Copies the List of SSID names to the ArrayList of Strings
- while(remembered.size()> count)
- {
- mStrings.add(count,remembered.get(count).SSID);
- count++;
- }
- }
- }
Parsed in 0.056 seconds, using GeSHi 1.0.8.4
My main.xml file code looks like this:
Using xml Syntax Highlighting
- XML:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ListView
- android:id="@+id/list_view"
- android:orientation="vertical"
- android:background="#ffffff"
- android:divider="#000000"
- android:textColor="#000000"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- </ListView>
- </LinearLayout>
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
The error I get when running the program is:
[2009-01-29 13:15:37 - DeviceMonitor]Error reading jdwp list: EOF
[2009-01-29 13:15:37 - DeviceMonitor]Connection Failure when starting to monitor device 'emulator-5554' : device (emulator-5554) request rejected: device not found
[2009-01-29 13:18:20 - DeviceMonitor]Error reading jdwp list: EOF
[2009-01-29 13:18:20 - DeviceMonitor]Connection Failure when starting to monitor device 'emulator-5554' : device (emulator-5554) request rejected: device not found
But the error is happening because I can't access the WIFI API's through the emulator, so what I do to test it is I copy my program's APK file, install it on my phone, and then run it from there.
PLEASE any sort of help here will be IMMENSELY appreciated as I seem to be stucked here for quite some time.
Thanks in advance,
Alex


