Android Native Scroller for a Data Grid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Android Native Scroller for a Data Grid

Post by keram » Sat Apr 05, 2014 3:32 am

Hello,

I would like to replace the standard scroller of the data grid in a standalone for Android with the native scrolling (by swipping).

On the card level I have this code:

Code: Select all

on openCard
      local tScrollerRect, tContentRect
   
   // Only create a scroller on a mobile device
   if environment() is not "mobile" then exit openCard
   
   // Set the area of the scroller
   put the rect of group "DataGrid 1" into tScrollerRect
   
   // Set the area of the content to be scrolled
  put 0,0,(the formattedWidth of group "DataGrid 1"),(the formattedHeight of group "DataGrid 1") into tContentRect
   
   // Create the scroller control
   mobileControlCreate "scroller", "loremScroll"
   put the result into sScrollerID
   
   // Set the properties of the scroller
   mobileControlSet "loremScroll", "rect", tScrollerRect
   mobileControlSet "loremScroll", "contentRect", tContentRect
   mobileControlSet "loremScroll", "visible", true
   mobileControlSet "loremScroll", "scrollingEnabled", true
   mobileControlSet "loremScroll", "vIndicator", true
   mobileControlSet "loremScroll", "vscroll", 0
   
end openCard

on closeCard
   // Delete the scroller
   if environment() is not "mobile" then exit closeCard
   mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of group "DataGrid 1" to vOffset
end scrollerDidScroll
I tried the same code for a group of objects and it works, but with data grid it does not.
The stack is attached.
Any ideas how to correct the code? Thanks.

keram
Attachments
android native scroller for data grid.zip
(34.88 KiB) Downloaded 209 times
Last edited by keram on Sat Apr 05, 2014 3:45 am, edited 2 times in total.
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Android Native Scroller Data Grid

Post by Simon » Sat Apr 05, 2014 3:35 am

Check out Hanson's answer in the comments here:
http://lessons.runrev.com/s/lessons/m/4 ... ll-a-field
Asked by Kevin

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Android Native Scroller for a Data Grid

Post by keram » Sat Apr 05, 2014 4:57 pm

Thanks Simon for the tip.

Hanson's suggestion was:
"...make the datagrid as big as you need it to be so you can fit all of the data on one page, that way removing its own scrollers. The result could then be added to a group that is controlled by the native mobile scrollers."

I did that (see the attached stack) and it still does not work.
Besides this when making the dg so big as to fit 640 text lines without the scroller the height of it is about 16000! Then it takes loooong time to start up such an app. I guess it's because all the lines are being loaded at once, while with the scroller just the visible lines are loaded. (The attached stacks has only 15 lines).

There must be something that must be done more directly with the data grid. I wish Zryip TheSlug would be around...

keram
Attachments
android native scroller for data grid2.zip
(12.01 KiB) Downloaded 196 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Android Native Scroller for a Data Grid

Post by Klaus » Sat Apr 05, 2014 6:55 pm

Hi keram,

a datagrid is not an ordinary group, so you need to take that into account :D

Change this:

Code: Select all

...
 // Set the area of the content to be scrolled
  ## put 0,0,(the formattedWidth of group "DataGrid 1"),(the formattedHeight of group "DataGrid 1") into tContentRect
  put 0,0,(the DGformattedWidth of group "DataGrid 1"),(the DGformattedHeight of group "DataGrid 1") into tContentRect
...
And this:

Code: Select all

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   ##  set the vScroll of group "DataGrid 1" to vOffset
   set the DGvScroll of group "DataGrid 1" to vOffset
end scrollerDidScroll
Best

Klaus

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Android Native Scroller for a Data Grid

Post by keram » Tue Apr 08, 2014 2:00 am

Hi Klaus,

Thanks for your corrections!
I delayed to answer because I was testing it in different ways.
The scrolling works OK when "All Lines" are selected but when only 1of the categories are selected or "My selection" view then the scrolling does not work.
I'm not sure if it's a glitch in the scrolling code or the code for saving the data - see my other post: "how to save data on mobile (android)".
Once I get that sorted out I'll give you another feedback.

keram
Attachments
android native scroller for data grid3.zip
corrected script
(32.8 KiB) Downloaded 227 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Android Native Scroller for a Data Grid

Post by keram » Tue Apr 08, 2014 12:03 pm

Hi Klaus,

Basically your fix is working OK - thanks! :)
There is some glitch with scrolling - see my other post here:
http://ftp.runrev.com/forums/viewtopic. ... ed#p100941
but I don't know what it depends on.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply