Kotlin

Create screens placeholders

You will now create placeholders for screens in the application (we will define layouts and the functionality in following steps of this tutorial). You will create a few files for each screen:

  • Layout
  • Fragment (view)
  • ViewModel (manages the view)

Login screen

To create layout right click on res/layout folder, select New > Layout Resource File, enter fragment_login as file name and press OK.

To create fragment right click on com.vonage.tutorial.messaging package, select New > Kotlin Class/File, enter LoginFragment as file name and select Class.

Replace the file contents with below snippet:

package com.vonage.tutorial.messaging

import androidx.fragment.app.Fragment

class LoginFragment : Fragment()

To create view model right click on com.vonage.tutorial.messaging package, select New > Kotlin Class/File, enter LoginViewModel as file name and select Class.

Replace the file contents with below snippet:

package com.vonage.tutorial.messaging

import androidx.lifecycle.ViewModel

public class LoginViewModel : ViewModel() {

}

Chat screen

To create layout right click on res/layout folder, select New > Layout Resource File, enter fragment_chat as file name and press OK.

To create fragment right click on com.vonage.tutorial.messaging package, select New > Kotlin Class/File, enter ChatFragment as file name and select Class.

Replace the file contents with below snippet:

package com.vonage.tutorial.messaging

import androidx.fragment.app.Fragment

class ChatFragment : Fragment()

To create view model right click on com.vonage.tutorial.messaging package, select New > Kotlin Class/File, enter ChatViewModel as file name and select Class.

package com.vonage.tutorial.messaging

import androidx.lifecycle.ViewModel

public class ChatViewModel : ViewModel() {

}

Run Build > Make project to make sure project is compiling.