Problems with ListView when collecting WIFI information

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problems with ListView when collecting WIFI information

Postby arocha55 » Thu Jan 29, 2009 8:09 pm

Dear Anddev community,

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Java:
  2.  
  3. package com.android.wifi.manager;
  4.  
  5.  
  6.  
  7. import java.util.ArrayList;
  8.  
  9. import java.util.List;
  10.  
  11.  
  12.  
  13. import android.app.Activity;
  14.  
  15. import android.app.AlertDialog;
  16.  
  17. import android.app.ListActivity;
  18.  
  19. import android.app.ProgressDialog;
  20.  
  21. import android.content.Context;
  22.  
  23. import android.content.Intent;
  24.  
  25. import android.net.wifi.ScanResult;
  26.  
  27. import android.net.wifi.WifiConfiguration;
  28.  
  29. import android.net.wifi.WifiManager;
  30.  
  31. import android.os.Bundle;
  32.  
  33. import android.util.Log;
  34.  
  35. import android.view.View.OnClickListener;
  36.  
  37. import android.widget.ArrayAdapter;
  38.  
  39. import android.widget.Button;
  40.  
  41. import android.widget.ListView;
  42.  
  43. import android.widget.TextView;
  44.  
  45. import android.content.DialogInterface;
  46.  
  47.  
  48.  
  49.  
  50.  
  51. public class Main extends Activity {
  52.  
  53.  
  54.  
  55.     List<WifiConfiguration> remembered;
  56.  
  57.     WifiManager wifi;
  58.  
  59.     ListView mylistview = (ListView)findViewById(R.id.list_view);
  60.  
  61.      
  62.  
  63.     int count=0;
  64.  
  65.     int i=0;
  66.  
  67.     int k=0;
  68.  
  69.     int idx=0;
  70.  
  71.    
  72.  
  73.      
  74.  
  75.     @Override
  76.  
  77.     public void onCreate(Bundle savedInstanceState) {
  78.  
  79.         super.onCreate(savedInstanceState);
  80.  
  81.         setContentView(R.layout.main);
  82.  
  83.        
  84.  
  85.         // Create the ArrayList of Strings
  86.  
  87.         ArrayList<String> mStrings = new ArrayList<String>();
  88.  
  89.        
  90.  
  91.         // Create and link the ArrayAdapter to the ArrayList of Strings
  92.  
  93.         ArrayAdapter<String> aa;
  94.  
  95.         aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
  96.  
  97.                mStrings);
  98.  
  99.         mylistview.setAdapter(aa);
  100.  
  101.        
  102.  
  103.        
  104.  
  105.        
  106.  
  107.         // Access to the WiFiManager API and initializes it.
  108.  
  109.         wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  110.  
  111.      
  112.  
  113.      
  114.  
  115.         // Access to the currently configured networks stored on your device.
  116.  
  117.         remembered = wifi.getConfiguredNetworks();
  118.  
  119.        
  120.  
  121.  
  122.  
  123.         // Copies the List of SSID names to the ArrayList of Strings
  124.  
  125.           while(remembered.size()> count)
  126.  
  127.          {
  128.  
  129.          mStrings.add(count,remembered.get(count).SSID);
  130.  
  131.          count++;
  132.  
  133.          }
  134.  
  135.          
  136.  
  137.              
  138.  
  139.      }
  140.  
  141. }
Parsed in 0.070 seconds, using GeSHi 1.0.8.4





My main.xml file code looks like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. XML:
  2.  
  3. <?xml version="1.0" encoding="utf-8"?>
  4.  
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.    android:orientation="vertical"
  8.  
  9.    android:layout_width="fill_parent"
  10.  
  11.    android:layout_height="fill_parent">
  12.  
  13.    <ListView
  14.  
  15.    android:id="@+id/list_view"
  16.  
  17.    android:orientation="vertical"
  18.  
  19.    android:background="#ffffff"
  20.  
  21.    android:divider="#000000"
  22.  
  23.    android:textColor="#000000"
  24.  
  25.    android:layout_width="fill_parent"
  26.  
  27.    android:layout_height="fill_parent"
  28.  
  29.    >
  30.  
  31. </ListView>
  32.  
  33. </LinearLayout>
Parsed in 0.002 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
arocha55
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jan 27, 2009 12:53 am

Top

Postby MrSnowflake » Fri Jan 30, 2009 9:29 am

Please don't double post, if we can help you, we will help you in the original thread, and if we can't help you, you won't get help using 2 different threads either. Locked
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests