Embarcadero has some sample code up which shows you how to do a pull or swipe down to refresh a TListView. A lot of mobile apps like Facebook use this functionality instead of having a refresh button. It saves screen real estate by not having an extra button to deal with. The idea is that you are at the top of the list and you put your finger down on the list and swipe or pull down. The list drags down and then you show a activity spinner above the list. Once the update is complete and the list gets updated the activity spinner goes away. The blog post talks about being for IOS but this will work on both Android and IOS. The code is simple enough and just checks the ScrollViewPos property of TListView. Take a look:
procedure TForm.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
begin
if not Updating and (ListView1.ScrollViewPos < -40) then
begin
Updating := true;
AniIndicator1.Visible := True;
AniIndicator1.Enabled := true;
for
I := Myposition + 1 to Myposition +20 do
begin
LItem := ListView1.Items.Add;
LItem.Text := Format(’Text %d’, [I]);
end;
inc(myposition, 20);
end;
end;
You could combine this code with the TListView RSS viewer demo.
Check out the full blog post and example from Embarcadero.
Update: Download Delphi XE5 Firemonkey Pull To Refresh Demo for Android
This really works on iOS but it doesn’t work on Android :/ . You can’t drag the listview off the screen the way you can with iOS. Are there any modifications one should do first?
Well that is a bummer. It should still be possible on Android you would just have to implement the drag part yourself. I don’t have any code handy right now but you could put the TListview inside of a vertical scroll box and then in mouse move or the gesture section if the TListview scroll position is at 0 start adding to the TListview Y until it’s greater than 40 and then continue with the rest of the code.
Technically you could also look at how it is done in the source code of the TListview for IOS and then bring that code over to the Android version.
I uploaded a pull to refresh demo for Android.
http://www.fmxexpress.com/wp-content/uploads/2014/02/PullToRefresh.zip
wtf? When RefreshPos is not 0?
Hey I didn’t say the code was going to make sense 😛
RefreshPos isn’t needed. Looks like I was probably going to use it and then ended up with the PullToRefreshCheck boolean instead.
Excuse me, ListView on how to realize the data load
How to paginate TListView with FireDac?
I’m trying to use TListView with records on demand, like paginate. How can I implement that with FireDac?
I think it would be possible with TFDLocalSQL. Have your normal query with all of the results and then connect TFDLocalSQL to those results and do your LIMIT page based where against the real results. Then display those 10-20 items in the TListView. You’ll have to come up with a way to navigate between pages though. Either some kind of scroll trigger or just page next and back buttons.
http://docwiki.embarcadero.com/RADStudio/XE8/en/Local_SQL_%28FireDAC%29
With a custom FDQuery is possible to paginate. My doubts are on TListView. I think the better way to request a new records demand is on user push up the listview and the listview is showing the last record. So, how to get the last showing record on listview?
*Note: If you execute at design time a query in TFDQuery, you will see the grid being paginated with a large resultset…