Search code examples
androidfunctionkotlinapk

Launching code from view: View immediately after launching the app


How can I run code that needs the view: View argument immediately after launching the app? For example, change the text mytext.text = "Hello World!" immediately after launch? How can I do this if I need a function with the arguments view: View, but the function can't run itself. Please help.


Solution

  • you can use a Handler and tell it after some milli seconds do an action for you after the launch :

    Handler().postDelayed({
                myView.text = "some text"
            }, 1000)//1 second
    

    if you are using an activity use it in onCreate() and if you are using a fragment use it in onCreateView()