1

I'm working on one of my first Android apps in which I load some JSON from the web and, after parsing, display the data in a ListView. When the app first launches, the ListView is empty. After the data is loaded, it's quite full. However, even while using notifyDataSetChanged() on my adapter, the ListView doesn't refresh and show the newly-loaded data until I press a key on the simulator's keyboard.

This is the processing I perform. I download the JSON, parse it, then my code looks like this - now, nothing shows at all, not even when pressing a key:

JSONArray jObject = new JSONArray(new2);
int l = jObject.length();
downloadedArrayOfStrings = new String[jObject.length()];

for(int i = 0; i < l; i++){
    Log.v("i", ""+i);
    jObject.getJSONObject(i).getString("category").toString();
}

ArrayList<String> lst = new ArrayList<String>();
lst.addAll(Arrays.asList(downloadedArrayOfStrings));
newAdapter = new MobileArrayAdapter(this, lst, downloadedArrayOfStrings);
newAdapter.setJSONArray(jObject);
setListAdapter(newAdapter);

Any ideas as to why this is happening, and how to fix it?

4

1 回答 1

0

您应该将 重新分配ListAdapterListView列表需要更新的时间。notifyDataSetChanged()不能ListAdapterCursorAdapter. _ 您也可以invalidateViews()在尝试我上面所说的之前尝试使用。invalidateViews()基本上会重建你的ListView.

于 2012-06-20T22:07:40.480 回答