ListActivity bug?

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

ListActivity bug?

Postby redswill » Thu Dec 04, 2008 7:33 pm

Hello,

I'm trying to make a ListActivity that gets the data to show from a website but it seems that something goes wrong and the list no longer gets updated (take a look at the code and you'll understand what I mean). Here is the code you can use to recreate this "error":

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ListTest extends ListActivity {
  2.  
  3.         private List<String> mItems = new ArrayList<String>();
  4.  
  5.         @Override
  6.         public void onCreate(Bundle savedInstanceState) {
  7.                 super.onCreate(savedInstanceState);
  8.                 setListAdapter(new ArrayAdapter<String>(this,
  9.                                 android.R.layout.simple_list_item_1, mItems));
  10.                 Thread thread = new Thread() {
  11.                         public void run() {
  12.                                 try {
  13.                                         mItems.add("This item shows up");
  14.                                         Log.d("Debug", mItems.get(mItems.size()-1));
  15.                                         try{
  16.                                                 DefaultHttpClient client = new DefaultHttpClient();
  17.                                                 HttpGet get = new HttpGet("http://google.com");
  18.                                                 HttpResponse response = client.execute(get);
  19.                                         }
  20.                                         catch(Exception e){};
  21.                                         mItems.add("This one doesn't");
  22.                                         Log.d("Debug", mItems.get(mItems.size()-1));
  23.                                 } catch (Exception e) {
  24.                                 }
  25.                         }
  26.                 };
  27.                 thread.start();
  28.         }
  29. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


So basically, what this does is show a list with only 1 item, when there should be 2.

This is what LogCat shows:

12-04 20:21:33.582: DEBUG/Debug(1115): This item shows up
12-04 20:21:34.641: INFO/ActivityManager(50): Displayed activity net.funmi.android/.ShowMoviesInterm: 1723 ms
12-04 20:21:34.842: DEBUG/dalvikvm(1115): GC freed 2981 objects / 186856 bytes in 75ms
12-04 20:21:35.321: DEBUG/dalvikvm(1115): GC freed 628 objects / 52344 bytes in 57ms
12-04 20:21:38.711: DEBUG/dalvikvm(1115): GC freed 1748 objects / 297720 bytes in 72ms
12-04 20:21:39.271: DEBUG/Debug(1115): This one doesn't

I also tried using a handler and the same thing happens...

mItems adds the second item as it should but somehow, the ArrayAdapter's getView() never gets called ...

Is there a bug in my code or is there a bug on Google's side?

Thank you!
redswill
Freshman
Freshman
 
Posts: 2
Joined: Thu Nov 27, 2008 12:28 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests