0

Logcat:

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もどこで更新すると思いますか?

4

1 に答える 1

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);
    }

このコードが完璧に機能することを確認してください。

于 2012-06-29T05:29:17.650 に答える