Page 1 of 1
native android scroller for 3-4 fields on 1 card [SOLVED]
Posted: Thu May 15, 2014 10:53 am
by keram
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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 11:11 am
by Simon
Hi keram,
I haven't gone through your stack carefully but for starters make sure you "mobileControlDelete" on closeCard.
Simon
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 11:27 am
by keram
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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 11:31 am
by Simon
Wow sorry I missed that.
It's late here, best I stop answering questions.
Simon
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 12:17 pm
by keram
No one can be super alert all the time; have a good rest
keram
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 5:57 pm
by keram
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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 6:03 pm
by Klaus
Hi Keram,
you variable gScrollField contains -> "c"
But should be just -> c
Don't add extra quotes:
Code: Select all
on mouseUp
put "c" into gScrollField
---
will do the trick.
Best
Klaus
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 6:16 pm
by keram
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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 6:23 pm
by Klaus
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?
Klaus wrote:Any other ideas?
Yes, store and use "the long id of fld xyz" in your global variable, never failed for me
Best
Klaus
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 7:03 pm
by keram
Thanks Klaus,
Klaus wrote:Yes, store and use "the long id of fld xyz" in your global variable, never failed for me

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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 7:13 pm
by Klaus
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?

Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 8:13 pm
by keram
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?

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
Re: native android scroller for 3-4 fields on 1 card
Posted: Thu May 15, 2014 9:46 pm
by Klaus
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?
If not, then you are safe
Know what I mean?
Unlike custom properties variables are NOT saved with the stack!
Best
Klaus
Re: native android scroller for 3-4 fields on 1 card
Posted: Fri May 16, 2014 1:07 am
by keram
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
Re: native android scroller for 3-4 fields on 1 card
Posted: Sat May 17, 2014 7:17 pm
by keram
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