Let’s define it.
- Create a variable to store user full name .
- And store call lastIndexof fun in a different variable with user full name
- After that define user first name and last name with substring in defferent defferent variables.
- Last call these variables in XML ids.
Our code should.
Val fullName = “Ansar Ali”
Val index = fullName?. lastIndexof (‘ ’)
val firstName = index?.let { it1 -> fullName?.substring(0, it1) }
val lastName = index?.plus(1)?.let { it1 -> fullName?.substring(it1) }
user_firstName.setText(firstName)
user_lastName.setText(lastName)
Hope it’s helpful.