2012-06-29 3 views
0

LogCat:ListView не уведомлен Adapter Change

06-28 22:21:11.031: E/AndroidRuntime(1282): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class android.widget.ArrayAdapter)] 

Код:

protected void onPostExecute(Void v) {   
     items.add(NewItem); 
     Collections.sort(items); 
     adapter.notifyDataSetChanged(); 
    } 

Вопрос: Где я полагаю, обновить ListView также?

+0

отправьте свой код doInBackground здесь. Вы можете обновлять listview только в onPostExecute. Я разместил ниже свой код, который отлично работает – Nirali

+0

Ваш код был всем, что мне нужно. Отлично! – KickingLettuce

+0

I сделал. Ждал истечения прошедшего времени. Еще раз спасибо. – KickingLettuce

ответ

1
@Override 
    protected Void doInBackground(Void... params) { 

     try { 
      arrayCountries = objwscountry.CountryCode(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 



@Override 
    protected void onPostExecute(Void result) { 
     super.onPostExecute(result); 

     progressDialog.dismiss(); 

     MyAdapter adapter = new MyAdapter(arrayCountries); 
     // apply the Adapter: 
     spinCountry.setAdapter(adapter); 
    } 

Просмотреть этот код работает отлично.