Radwa Radwa - 2 years ago 142
Android Question

Android Scroll ScrollView automatically in onCreate method

I have some kinde of calendar and I use ScrollView to scroll to days
I want it on create it will be scroll able to today date
here is the cod I use:

scrollV.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
scr.post(new Runnable() {
public void run() {
scrollV.scrollTo(0,3); }

3 is just for test I'll change it later; thanks in advance.

Answer Source

I solved it here is the answer for any one need it : Just put a timer in OnCreate method or in onCreateView if it is a fragment

new java.util.Timer().schedule(
                new java.util.TimerTask() {
                    public void run() {

day is the variable you want to the list to scroll to it's day of month for me , list is the list view

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download