我正在使用列表适配器并为其提供一个列表,该列表由TreeMap制作 树形图是必需的,因为我需要列表的数据来自三个地方,我需要收集它们然后根据时间戳进行排序。
现在,当新数据进入时,即使我调用notifyDataSetChanged(),适配器也不会更新。
我在下面附上了我的代码:
LinkedList<DeviceDataInfo> tsDataList = response
.getDeviceDataInfoList();
for (DeviceDataInfo data : tsDataList) {
// if (data.getAttrValue().equals("14")){
String eventMsg = null;
if (data.getAttrValue() != null) {
eventMsg = getEventMessage(
Float.valueOf(data.getAttrValue()),
data.getAttrName());
if (eventMsg != null) {
long time = data.getTime();
String eventDate = mCurrentDoorSensor
.getFormattedDate(time);
String eventTime = mCurrentDoorSensor
.getFormattedTime(time);
SensorListModel item = new SensorListModel(eventTime,
eventDate, eventMsg);
if (!mDoorSensorHistory.containsKey(time)) {
// add item to the tree
mDoorSensorHistory.put(time, item);
}
}
}
}
SensorListModel[] list = new SensorListModel[mDoorSensorHistory
.size()];
list = mDoorSensorHistory.values().toArray(list);
mList = new ArrayList<SensorListModel>(Arrays.asList(list));
mSensorProgressBar.setVisibility(View.GONE);
mSensorProgressBarText.setVisibility(View.GONE);
if (isAdded()) {
if (mSensorAdaptor == null) {
mSensorAdaptor = new SensorListAdaptor(getActivity(),
mList, "DOOR");
mSensorList.setAdapter(mSensorAdaptor);
} else {
// mSensorAdaptor = new SensorListAdaptor(getActivity(),
// mList, "DOOR");
((BaseAdapter) mSensorList.getAdapter())
.notifyDataSetChanged();
}
}
有人可以,让我知道出了什么问题? 感谢
答案 0 :(得分:0)
供将来参考:这解决了它
@Sunny:尝试mSensorAdaptor.addAll(list); mSensorAdaptor.notifyDataSetChanged();如果addAll方法不可用,那么你需要在SensorListAdaptor中定义addAll方法所有两个ArrayLists - ρяσѕρєяK15分钟前