DEV Community

Discussion on: Humble Views, Proud ViewModels

Collapse
 
_anpurnama profile image
Aditya Nanda Purnama

Hi, I've never seen an approach to Android view like this so thank you for writing this post.
And this approach also applicable for activity too?

Collapse
 
marcellogalhardo profile image
Marcello Galhardo • Edited

Hey, @_anpurnama , glad to hear that. 😄

Definitely! The same example with activities would look like the following:

class SignUpActivity : AppCompatActivity() {

    private val viewModel by TODO("ViewModel declaration")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val view = SignUpView(this)

        // Bind the View and ViewModel

        setContentView(view)
    }
}
Enter fullscreen mode Exit fullscreen mode

All other aspects are the same.