2012-06-29 34 views
0

logcat中的:ListView控件不通知適配器改變

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方法代碼。你只能在onPostExecute中更新listview。我已在下面發佈了我的代碼,該代碼非常完美 – Nirali

+0

您的代碼是我所需要的。完善! – KickingLettuce

+0

我做到了。等待時間過去了。再次感謝。 – 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); 
    } 

看到這段代碼作品完美。

相關問題