onCreateView added the following code to onCreateView and nothing works, and if I create a myButton button and add a listener to it when pressed, insert the same code, everything works, how to make everything work without pressing the button automatically when creating

myScroll = (ScrollView) view.findViewById(R.id.myScroll); myScroll.scrollTo(0, 0);

    2 answers 2

    And if so :

     new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { //Тут код выполнится чрез 0.5с myScroll.scrollTo(0,0); } }, 500); 

    ?

    • thanks, works - java
    • you can try without Handler - myScroll.postDelayed(new Runnable(){...},500); :) - Jarvis_J
    • @AbrogPetrovich, I had something in my head, but I didn’t want to give out such a design to Google. And IDE is not running) - Yuriyi

    If you call myScroll right away - it does not have time to initialize.
    Try this:

      myScroll.post(new Runnable() { @Override public void run() { myScroll.scrollTo(0,0); } }); 
    • did not help, is it onCreateView to add to onCreateView , or did I not understand correctly? - java