Skip to content
Snippets Groups Projects
Unverified Commit 901c9e36 authored by AC5636's avatar AC5636 :ghost:
Browse files

Refactor

parent 7f5d63d3
No related branches found
No related tags found
No related merge requests found
package com.example.e03builduiwithlayouteditor2 package com.example.e03builduiwithlayouteditor2
import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
...@@ -9,41 +8,44 @@ import android.widget.TextView ...@@ -9,41 +8,44 @@ import android.widget.TextView
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private val firstnames = arrayOf("Renato", "Rosangela", "Tim", "Barton", "Jeannette", "Ali", "Becky", "Coco", "Ragnar") private val firstNames = arrayOf("Renato", "Rosangela", "Tim", "Barton", "Jeannette", "Ali", "Becky", "Coco", "Ragnar")
private val lastnames = arrayOf("Ksenia", "MetLife", "Asuncion", "Zemfira", "Gang", "G", "G", "A", "B") private val lastNames = arrayOf("Ksenia", "MetLife", "Asuncion", "Zemfira", "Gang", "G", "G", "A", "B")
private val jobTitles = arrayOf("District Quality Coordinator","International Intranet Representative","District Intranet Administrator","Dynamic Research Manager","Central Infrastructure Consultant", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen") private val jobTitles = arrayOf("District Quality Coordinator","International Intranet Representative","District Intranet Administrator","Dynamic Research Manager","Central Infrastructure Consultant", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen", "Lorem ipsum dolor amit sen")
// function displays employees data in UI // function displays employees data in UI
private fun showEmployeeData(index: Int) { private fun showEmployeeData(index: Int) {
// data for the employee
val firstName = firstNames[index]
val lastName = lastNames[index]
val jobTitle = jobTitles[index]
val employeeInfo = getString(R.string.employee_info_text, lastNames[index], firstNames[index], jobTitles[index], getString(R.string.description))
var imageSrc = 1
when(index) {
0 -> imageSrc = R.drawable.employee1
1 -> imageSrc = R.drawable.employee2
2 -> imageSrc = R.drawable.employee3
3 -> imageSrc = R.drawable.employee4
4 -> imageSrc = R.drawable.employee5
5 -> imageSrc = R.drawable.employee6
6 -> imageSrc = R.drawable.employee7
7 -> imageSrc = R.drawable.employee8
8 -> imageSrc = R.drawable.employee9
}
// find TextView's from the UI layout file // find TextView's from the UI layout file
val firstNameTextview = findViewById<TextView>(R.id.first_name) val firstNameTextview = findViewById<TextView>(R.id.first_name)
val lastNameTextView = findViewById<TextView>(R.id.last_name) val lastNameTextView = findViewById<TextView>(R.id.last_name)
val jobTitleTextView = findViewById<TextView>(R.id.job_title) val jobTitleTextView = findViewById<TextView>(R.id.job_title)
val employeeInfoTextView = findViewById<TextView>(R.id.employee_info_text) val employeeInfoTextView = findViewById<TextView>(R.id.employee_info_text)
// Update TextView texts // Update TextView texts
firstNameTextview.text = firstnames[index] firstNameTextview.text = firstName
lastNameTextView.text = lastnames[index] lastNameTextView.text = lastName
jobTitleTextView.text = jobTitles[index] jobTitleTextView.text = jobTitle
employeeInfoTextView.text = employeeInfo
// info is
employeeInfoTextView.text = getString(R.string.employee_info_text, lastnames[index], firstnames[index], jobTitles[index], getString(R.string.description))
// image
var id = 0
when(index) {
0 -> id = R.drawable.employee1
1 -> id = R.drawable.employee2
2 -> id = R.drawable.employee3
3 -> id = R.drawable.employee4
4 -> id = R.drawable.employee5
5 -> id = R.drawable.employee6
6 -> id = R.drawable.employee7
7 -> id = R.drawable.employee8
8 -> id = R.drawable.employee9
}
// find imageView and display correct employee image // find imageView and display correct employee image
val imageView = findViewById<ImageView>(R.id.employee_image) val imageView = findViewById<ImageView>(R.id.employee_image)
imageView.setImageResource(id) imageView.setImageResource(imageSrc)
} }
// function will be called from the UI // function will be called from the UI
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment