Question

I am using a list adapter and feeding a list to it, which is made from a TreeMap.
Treemap is required as I need that the data for the list comes from three places and I need to collect it all and then have it sorted basing on a time stamp.

Now, when the new data comes in, the adapter doesn't update, even when I call notifyDataSetChanged().

I have attached my code below:

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

                }
            }

Could someone, please, let me know what is going wrong? Thanks

Was it helpful?

Solution

For future reference: This solved it

@Sunny : try mSensorAdaptor.addAll(list);mSensorAdaptor.notifyDataSetChanged(); if addAll method is not available then you will need to define addAll method in SensorListAdaptor which all two ArrayLists – ρяσѕρєя K 15 mins ago

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top