Android Question ScrollView not autoscrolling properly

davidvidasoft

Member
Licensed User
Hello, I have a problem when doing some debugging to my app. I've added a line to my code that makes a scrollpane to scroll to the bottom:
B4X:
svOptions.ScrollPosition = svOptions.Panel.Height
adapted from an example from here https://www.b4x.com/android/forum/threads/scrollview-automatically-scroll-to-the-bottom.27018/
sv.ScrollPosition = sv.Panel.Height

Now, the problem comes when I run the app. The automatic scrolling didn't work so I set a breakpoint there to see what happened and, to my surprise, it worked as I had expected. I cleared the breakpoint and restarted the app and the autoscroll stopped working again.

I've already cleared the whole project with the IDE tool. Also tried unistalling the app on the phone and reinstalling after clearing the project again but nothing. What can I do to fix this problem?
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
It might have worked with a breakpoint because it caused a delay in execution & the message queue was able to catch up. Try putting Sleep(0) on the line above the line you added & see if that helps.

Failing that, post the entire sub on here & we might be able to see what's causing the issue...

- Colin.
 
Upvote 0

davidvidasoft

Member
Licensed User
It worked fine with a Sleep(0) line above. Thanks for the help.
You can use ScrollView.ScrollToNow if you want it to change immediately.
Replacing it with that line worked just as before but using Sleep(0) fixed it in both cases Thanks
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Errrr - a bit more info about your latest issue might make it easier to help you...

For us "old" ex-Visual Basic developers, Sleep(x) is generally used wherever a DoEvents might have been needed. Eg: If you have a loop that loads a long list of values into a listview, you would put Sleep(0) at the end of each iteration so that the list updates as it's being loaded - otherwise the user is sitting there looking at a screen that's doing nothing until the loading loop has completed.

In other words, anywhere you have a long process that runs on the UI thread is a good candidate for using Sleep(x).

- Colin.
 
Upvote 0

davidvidasoft

Member
Licensed User
Errrr - a bit more info about your latest issue might make it easier to help you...
Uh, oh. I made a post about it, should have linked it before: https://www.b4x.com/android/forum/threads/problem-making-a-sqlite-query.83276/
Now I get that it is not related with the DoEvent/Sleep(0) thing but still don't know why it happens.

Thanks for the help there. Didn't know it was possible to do that.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…