We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfListView - reset view after change item source

Thread ID:

Created:

Updated:

Platform:

Replies:

142708 Feb 15,2019 04:41 PM UTC Mar 9,2019 04:13 PM UTC Xamarin.Forms 8
loading
Tags: SfListView
Tomas Turek
Asked On February 15, 2019 04:41 PM UTC

I am using SfListView and I want autoupdate values (change itemsource) every 5 seconds.
I would like to keep the current position in the scroll after refreshing the ItemsSource collection. I want it without animation.

----------------------------------------------
First i use this: 

ExtendedScrollView scrollView = new ExtendedScrollView(); 
scrollView = ListView.GetScrollView();
ListViewG.ItemsSource = itemList;
ListView.ScrollTo(scrollView.ScrollY);

Works good but with animation. I don´t want it.

------------------------------------------
Then i use: 

VisualContainer visualContainer = new VisualContainer();
visualContainer = ListView.GetVisualContainer();
var scrollLineIndex = visualContainer.ScrollRows.ScrollLineIndex;
ListViewG.ItemsSource = itemList;
ListViewGridTechnology.LayoutManager.ScrollToRowIndex(scrollLineIndex, true);

Works only on iOS. Android only change listview on start position after update.
-------------------------------------------------------


Next problem: if I use the second variant, there is a problem with big items. After update, the last one is not displayed correctly. (Attach picture)
Standard ListView work without reset position

Attachment: update_5b65cee2.zip

Sangeetha Raju [Syncfusion]
Replied On February 18, 2019 12:38 PM UTC

Hi Tomas, 
 
Thanks for contacting Syncfusion Support. 
 
Currently we are analyzing the mentioned query with reset view after change item source SfListview Xamarin Forms. We will check and let you know the details in three business days (Feb 21, 2019). We appreciate your patience until then. 
 
Regards, 
Sangeetha Raju 


Gnana Priya Namasivayam [Syncfusion]
Replied On February 21, 2019 01:14 PM UTC

Hi Tomas, 
  
  
We have checked the reported query based on the shared image from our side. We would like to know that item scrolls to end of the list when last index passed to ScrollToRowIndex method and make full item in view in our sample. Can you let us know the purpose of using scroLineIndex instead lastItemCount. We have prepared sample for your reference, please find the sample from below. 
 
  
Can you please check with the above sample whether the issue occurs in our sample also. If no please revert us back with the modified sample. So that we can analyse the cause of issue and provide you the better solution at our end. 
 
 
Regards, 
Gnana Priya N 


Gnana Priya Namasivayam [Syncfusion]
Replied On February 21, 2019 05:47 PM UTC

Hi Tomas, 

You can refer sample from below link for your reference. Please ignore the sample from previous update. 

Sample Link : ListViewSample 


Regards, 
Gnana Priya N  


Tomas Turek
Replied On February 22, 2019 12:01 PM UTC

Hi, thank you for samples, but I still don´t know how to resolve my problem with reset position of view after change (refreshing) item source without animation.

I created a small sample with 2 tabviews. I have implemented a progress bar and timer (5 seconds) for a refresh.

First tabview (Auto-update 1):
- Android: after reset item source the view scroll to position correctly, but with animation
- iOS:  after reset item source the view scroll to start position

Second tabview (Auto-update 2):
- Android: after reset item source the view scroll to start position
- iOS:  after reset item source the view scroll to position of first visible row index - but there is a problem with last row (it does not show correctly)

Standard xamarin listview doesn´t reset position after change item source. How to implement the same function in SfListView? (same position without animation effect)
Can you provide any solution or implement it into my sample?
Thank you

Attachment: SampleListViewUpdate_2f82f3a4.zip

Jayaleshwari N [Syncfusion]
Replied On February 25, 2019 12:04 PM UTC

  
We have checked the attached sample from our side. We would like to let you know that items didn't load completely in view when you scroll items using ScrollToRowIndex which only scroll items in view based in index. Therefore, you need to set some delay to load items completely. We would also like to know that ScrollLineIndex will only set the index of first visible line in the body region to view. In order to make, Last line index to be in view completely you can either set visualContainer.ScrollRows.LastBodyVisibleLine (Last line index of the view) or ItemsSource.Count()-1 (Last index of the collection). We have modified and attached the sample page of AutoUpdate 2 tabview for your reference and you can download the same from the following location 
  
  
Please let us know whether sample meets your requirement.  
  
Regards,  
Jayaleshwari N 


Tomas Turek
Replied On March 5, 2019 04:30 PM UTC

Thank you for your sample.
1) I tried 'delay' and it seems to be better than before, but I don't know how to choose the right time to delay. Because listview can contain 5 items or contain 500 items (not fix count). If I use:
   -- await Task.Delay(50); - sometimes listview stay on top (don´t scroll to position)
   -- await Task.Delay(1000); - jump to start and then jump to position
So I will try randomly trying to set the right number for my phone. But I don't think, that is a pretty solution.

2) Lost position. If I try:
     -- ScrollLineIndex  - after resetting item source the view scroll to the position of first visible row index - but there is a problem with the last row (it does not show correctly)
    -- LastBodyVisibleLineIndex - the list view scroll to the end (every time)

But I want to stay in the same position as it was before update items. (If I am in middle I want to stay middle, - if my position is last a want to stay on the last position - ...) - in my sample (page Auto-update 1) stay the same position after update (but I want it without animation)  .. ScrollLineIndex and LastBodyVisibleLineIndex doesn´t work as I want. Same way as standard xamarin listview.

Can you provide any solution for how to do it, please? How to stay in the same position after update item source without animation.


Gnana Priya Namasivayam [Syncfusion]
Replied On March 6, 2019 02:09 PM UTC

Hi Tomas, 
 
We are currently checking on the reported query from our side. We will validate and provide further details on or before March 8, 2019. We will appreciate your patience until then. 
 
Regards, 
Gnana Priya N

 


Gnana Priya Namasivayam [Syncfusion]
Replied On March 9, 2019 04:13 PM UTC

Hi Tomas, 
 
Please find the below details for your query : 
 
# Regarding issue with delay. 
 
You can call ScrolLineIndex method in separate thread to avoid maximum delay when you have large set of ItemsSource collection. 
 
#Regarding last item clipping issue : 
 
You can only pass ScrolLineIndex in order to retain the index( in ScrolToRowIndex method) to which the items gets scrolled before ItemsSource update like Scrolposition in `ScrolTo` method. Here, ScrolLineIndex takes the first body visible line index which displays the first visible item in view correctly even after item source update but you are focusing the last item to be in view as per your requirement. To make last item in view completely, you can pass line index by adding 1 especially for the bring the last item in view.  
 
We have attached the modified sample for your reference, please find the sample from below. 
 
 
 
ListViewValue2.ItemsSource = itemList2; 
if (scrolLineIndex != itemList2.Count() - 1) 
{ 
   Device.BeginInvokeOnMainThread(async () => 
   { 
     await Task.Delay(100); 
     ListViewValue2.LayoutManager. 
ScrollToRowIndex(scrolLineIndex+1, true); 
   }); 
} 
else 
{ 
    Device.BeginInvokeOnMainThread(async () => 
    { 
      await Task.Delay(100); 
      ListViewValue2.LayoutManager.ScrollToRowIndex(scrolLineIndex, true); 
    });  
} 
 
 
 
Please let us know whether sample meets your requirement. 
 
Regards, 
Gnana Priya N 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon