adapter.notifyDataSetChanged();是不是在Android中工作我正在檢索for循環中的值,但值不顯示在屏幕上。 我的Java文件:NotifyDataSetChanged在我的代碼中不起作用
private static final String TAG_NAME="Notification";
String[] resultsAsString = {""};
ListView listView;
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, resultsAsString);
ParseQuery<ParseObject> parseObjectParseQuery=new ParseQuery<ParseObject>("PushNotifications");
parseObjectParseQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e==null){
resultsAsString = new String[objects.size()];
Log.d(TAG_NAME,"Objects size in MyService is:"+objects.size());
if(objects.size()>0){
Log.d(TAG_NAME,"Object size is "+objects.size());
for(int index = 0; index < objects.size(); index++){
resultsAsString[index] = objects.get(index).getString("Message");
Log.d(TAG_NAME,"result value is:"+resultsAsString[index]);
}
adapter.notifyDataSetChanged();
}else {
Log.d(TAG_NAME,"Object size is "+objects.size());
}
}
}
});
listView = (ListView) findViewById(R.id.notificatio_listView);
listView.setAdapter(adapter);
我的logcat顯示: 對象大小爲MyService是:3 對象大小爲3 第一Nottification 第二消息 第三則消息
你確定objects.size()是> 0嗎? – Opiatefuchs
我確信對象大小是3,我可以查看for循環 –
和...通常,在將適配器設置爲listView後調用adapterNotifyDataSetChanged()...... – Opiatefuchs