native android scroller for 3-4 fields on 1 card [SOLVED]

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

native android scroller for 3-4 fields on 1 card [SOLVED]

Post by keram » Thu May 15, 2014 10:53 am

Hello,

I'd like to create a card with 3-4 text fields each having a native android scrollers. I followed the lesson here http://lessons.runrev.com/s/3527/m/4069 ... ll-a-field and managed to create such a field on 1 card. Then I tried to use the same code for another card with 3 fields that I grouped together and coded so that the group will have a native scroller. Each text field can be made visible by a separate button on that card.
It did not work out - the fields do not scroll.

The code is:

Code: Select all

local sScrollerID
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 grp "abc"  into tScrollerRect

   // Set the area of the content to be scrolled
   put 0,0,(the formattedWidth of grp "abc"),(the formattedHeight of grp "abc") into tContentRect

   // Create the scroller control
   mobileControlCreate "scroller", "myScroll"
   put the result into sScrollerID

   // Set the properties of the scroller
   mobileControlSet "myScroll", "rect", tScrollerRect
   mobileControlSet "myScroll", "contentRect", tContentRect
   mobileControlSet "myScroll", "visible", true
   mobileControlSet "myScroll", "scrollingEnabled", true
   mobileControlSet "myScroll", "vIndicator", true
   mobileControlSet "myScroll", "vscroll", 0
end openCard

on closeCard
   // Delete the scroller
   if environment() is not "mobile" then exit closeCard
   set the vScroll of grp "abc" to 0
   mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of grp "abc" to vOffset
end scrollerDidScroll
Is it something wrong in the code, or is it not possible to have more than 1 field scrolling on a card?
stack is attached

keram
Attachments
scroll 3-4 fields on the same card.zip
(87.42 KiB) Downloaded 233 times
Last edited by keram on Sat May 17, 2014 7:18 pm, edited 1 time 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: native android scroller for 3-4 fields on 1 card

Post by Simon » Thu May 15, 2014 11:11 am

Hi keram,
I haven't gone through your stack carefully but for starters make sure you "mobileControlDelete" on closeCard.

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: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 11:27 am

Yes, it there in the code:
on closeCard
// Delete the scroller
if environment() is not "mobile" then exit closeCard
set the vScroll of grp "abc" to 0
mobileControlDelete sScrollerID
end closeCard
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: native android scroller for 3-4 fields on 1 card

Post by Simon » Thu May 15, 2014 11:31 am

Wow sorry I missed that. :oops:
It's late here, best I stop answering questions.

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: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 12:17 pm

No one can be super alert all the time; have a good rest :)
keram
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: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 5:57 pm

One idea for solution that I've got is to place a global variable in the card (global gScrollField) then replace the grp "abc" in the above script with
field gScrollField.

Then add this in each button (here for fld "c") that shows the particular field:
global gScrollField
on mouseUp
put quote & "c" & quote into gScrollField
hide fld "a"
hide fld "b"
show fld "c"
end mouseUp

and similar for fields a and b

and then hope for the best...
But unfortunately this trick did not work. But maybe there is just one little thing that I have to change in addition to the above?? What could this be?

keram
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: native android scroller for 3-4 fields on 1 card

Post by Klaus » Thu May 15, 2014 6:03 pm

Hi Keram,

you variable gScrollField contains -> "c"
But should be just -> c
:D

Don't add extra quotes:

Code: Select all

on mouseUp
  put "c" into gScrollField
  ---
will do the trick.


Best

Klaus

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

Re: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 6:16 pm

Hi Klaus,
Klaus wrote:you variable gScrollField contains -> "c"
Yes, exactly. Because in the card script fld gScrollField has to be replaced with fld "c" otherwise it will be fld c and so it does not work.

Any other ideas?

keram
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: native android scroller for 3-4 fields on 1 card

Post by Klaus » Thu May 15, 2014 6:23 pm

Hi Keram,
keram wrote:
Klaus wrote:you variable gScrollField contains -> "c"
Yes, exactly. Because in the card script fld gScrollField has to be replaced with fld "c" otherwise it will be fld c and so it does not work.
sure? 8)
Klaus wrote:Any other ideas?
Yes, store and use "the long id of fld xyz" in your global variable, never failed for me :D


Best

Klaus

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

Re: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 7:03 pm

Thanks Klaus,
Klaus wrote:Yes, store and use "the long id of fld xyz" in your global variable, never failed for me :D
Yes, that's not failing although I'm sure you meant put the name of fld "xyz" into gScrollField or the id and not the long id or the long name since the long ones are containing the absolute path and will not work on standalones.
So, yes the proper name of the fld is replaced to be for example field "c" but scrolling still does not work :(

So the quest continues...

keram
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: native android scroller for 3-4 fields on 1 card

Post by Klaus » Thu May 15, 2014 7:13 pm

keram wrote:Yes, that's not failing although I'm sure you meant put the name of fld "xyz" into gScrollField or the id and not the long id or the long name since the long ones are containing the absolute path and will not work on standalones.
No I meant LONG ID, not name or whatever!
And why do you think this does not work in standalones? 8)

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

Re: native android scroller for 3-4 fields on 1 card

Post by keram » Thu May 15, 2014 8:13 pm

Klaus wrote: keram wrote:Yes, that's not failing although I'm sure you meant put the name of fld "xyz" into gScrollField or the id and not the long id or the long name since the long ones are containing the absolute path and will not work on standalones.


No I meant LONG ID, not name or whatever!
It works in the same way whether you use the name, the long name or the long ID.
Klaus wrote:And why do you think this does not work in standalones? 8)
Because when you sthe long name or ID you get this in the global variable:
field id 492661 of group id 739655 of card id 492663 of stack "H:/... here is the complete path to the stack -> /1 scroll 3-4 fields on the same card_ok when going back_2.livecode"
So I thought - how can this path be found in standalone running on another device???

But it seems to be OK.

Now the most important thing I discovered is that when opening the app the scrolling does not work. But if I go to another card on the same stack, just empty card, and return back to the main card the scrolling works like magic! So there is something in the card code that I don't understand and has to be amended, but what?

I'm attaching the stack.

keram
Attachments
scroll 3-4 fields on the same card_ok when going back from another card.zip
(60.85 KiB) Downloaded 193 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: native android scroller for 3-4 fields on 1 card

Post by Klaus » Thu May 15, 2014 9:46 pm

Hi Keram,
Because when you sthe long name or ID you get this in the global variable:
field id 492661 of group id 739655 of card id 492663 of stack "H:/... here is the complete path to the stack -> /1 scroll 3-4 fields on the same card_ok when going back_2.livecode"
So I thought - how can this path be found in standalone running on another device???
do you save the content of the global and RESTORE it on the target platform in the standalone? 8)
If not, then you are safe :D

Know what I mean?
Unlike custom properties variables are NOT saved with the stack!


Best

Klaus

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

Re: native android scroller for 3-4 fields on 1 card

Post by keram » Fri May 16, 2014 1:07 am

Klaus wrote:do you save the content of the global and RESTORE it on the target platform in the standalone?
No, I don't. Thanks for clarifying this.

So now what remains to clarify and correct is that fact that it works only when I return to the card from another one.

keram
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: native android scroller for 3-4 fields on 1 card

Post by keram » Sat May 17, 2014 7:17 pm

I've got it fixed by splash21 on StackExchange. Here is the solution:

The problem was that gScrollField was not defined until one of the a,b,c buttons was pressed : it initially caused the preOpenCard handler to fail.
So he modified the card script to:

Code: Select all

global gScrollField
    local sScrollerID
    local sStarted

    on preOpenCard
       local tScrollerRect, tContentRect

       if sStarted <> true then
          put the long id of fld "a" into gScrollField
          hide fld "c"
          hide fld "b"
          show fld "a"
          put true into sStarted
       end if

       // Only create a scroller on a mobile device
       if environment() is not "mobile" then exit preOpenCard
       .....
       .....
       .....
The sStarted variable initializes things the first time it executes.

Thanks again splash21! :)

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

Post Reply