List Refresh

kefikefi Member ✭✭✭
edited September 26 in Xamarin.iOS

When we call api using timer and refresh the list.
Please see the link below:

https://drive.google.com/file/d/1wmBndDiYdPu78kkLRUm8apMd7wW9au4P/view?usp=sharing

Tagged:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Please post your code .

  • kefikefi Member ✭✭✭
    edited October 3

    private ObservableCollection _avaliableKEFIPlaces = new ObservableCollection();

        public ObservableCollection<AvailableKEFIPlaceModel> AvaliableKEFIPlaces
        {
            get { return _avaliableKEFIPlaces; }
            set { _avaliableKEFIPlaces = value; RaisePropertyChanged(nameof(AvaliableKEFIPlaces)); }
        }           
    
    
    
    
        if (res.result != null)
                        {
                            var responcedata = res.result;
                            _avaliableKEFIPlaces.Clear();
                            int counter = 0;
                            foreach (var items in res.result)
                            {
                                var availableKEFI = new AvailableKEFIPlaceModel
                                {
                                    AvailablePlace = items.location,
                                    Logo = "kefi",
                                    id = counter++
                                };
                                availableKEFI.mac = items.mac_address;
                                availableKEFI.DeviceType= items.device_type.ToString();
                                availableKEFI.Value = items.online_status;
                                availableKEFI.Status = items.online_status.Equals("0") ? "Offline" : "Online";
                                if (availableKEFI.DeviceType == "1")
                                {
                                    availableKEFI.deleteshow = true;
                                }
                                else
                                {
                                    availableKEFI.deleteshow = false;
                                }
                                if (availableKEFI.Status == "Offline")
                                {
                                    availableKEFI.statusvalue2 = true;
                                    availableKEFI.statusvalue1 = false;
                                    if(availableKEFI.DeviceType == "0")
                                        LocalSettings.InternetStatus = 0;
                                }
                                else
                                {
                                    availableKEFI.statusvalue1 = true;
                                    availableKEFI.statusvalue2 = false;
                                    if (availableKEFI.DeviceType == "0")
                                        LocalSettings.InternetStatus = 1;
                                }
                                availableKEFI.boxcmd = items.device_type == 1 ? "mesh" : "main_kefi";
                                _avaliableKEFIPlaces.Add(availableKEFI);
                                LocalSettings.DeviceData = res.result;
                            }
                            int OnlineKefiCount = AvaliableKEFIPlaces.Where(x => x.Value == "1").Count();
                            OnlineKefiCount = counter;
                            KefiStatus = "Total KEFI Devices :  " + OnlineKefiCount.ToString();
                            IsBusy = false;
    
                        }
    

    private void StartTimerForNetwork()
    {
    Device.StartTimer(System.TimeSpan.FromSeconds(8), () =>
    {
    Device.BeginInvokeOnMainThread(() =>
    {

                        GetDeviceList();
                    }
                });
                return true;
            });
        }
    
  • ColeXColeX Member, Xamarin Team Xamurai

    What's the exact problem ? You mean the blinking animation ?

  • kefikefi Member ✭✭✭

    Actually i want to list static when api call.

  • ColeXColeX Member, Xamarin Team Xamurai

    Your listView bind with AvaliableKEFIPlaces Which is a ObservableCollection, data change will trigger the change on View, so when _avaliableKEFIPlaces.Clear(); executed , your listview will be blank .

    Assign the data to _avaliableKEFIPlaces directly , don't execute Clear + Add operation .

    Modify code as

    if (res.result != null)
                    {
                        var responcedata = res.result;
                        // _avaliableKEFIPlaces.Clear();   remove this line 
                        int counter = 0;
    
                        ObservableCollection<AvailableKEFIPlaceModel> tempList = ObservableCollection<AvailableKEFIPlaceModel>  // inercome list
                        foreach (var items in res.result)
                        {
                            var availableKEFI = new AvailableKEFIPlaceModel
                            {
                                AvailablePlace = items.location,
                                Logo = "kefi",
                                id = counter++
                            };
                            availableKEFI.mac = items.mac_address;
                            availableKEFI.DeviceType= items.device_type.ToString();
                            availableKEFI.Value = items.online_status;
                            availableKEFI.Status = items.online_status.Equals("0") ? "Offline" : "Online";
                            if (availableKEFI.DeviceType == "1")
                            {
                                availableKEFI.deleteshow = true;
                            }
                            else
                            {
                                availableKEFI.deleteshow = false;
                            }
                            if (availableKEFI.Status == "Offline")
                            {
                                availableKEFI.statusvalue2 = true;
                                availableKEFI.statusvalue1 = false;
                                if(availableKEFI.DeviceType == "0")
                                    LocalSettings.InternetStatus = 0;
                            }
                            else
                            {
                                availableKEFI.statusvalue1 = true;
                                availableKEFI.statusvalue2 = false;
                                if (availableKEFI.DeviceType == "0")
                                    LocalSettings.InternetStatus = 1;
                            }
                            availableKEFI.boxcmd = items.device_type == 1 ? "mesh" : "main_kefi";
                            tempList.Add(availableKEFI);
                            LocalSettings.DeviceData = res.result;
                        }
    
             _avaliableKEFIPlaces  = tempList
    
Sign In or Register to comment.