Lazuardy
Jun 1, 2021

i think you're misunderstood how viewmodel works in android. viewmodel class is automatically initialized when onCreate of your activity is called. and will live as long as onDestroy is not called. so if your activity / fragment already uses a viewmodel, and you want to set a button onClickListener, the viewmodel is already been created, and you can just use the viewmodel's method inside your button onClickListener

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Lazuardy
Lazuardy

Written by Lazuardy

We help businesses through bleeding edge technology — www.lazuardy.tech.

No responses yet

Write a response