Complete Newbie to Kotlin, trying to get three values to pass across from text boxes to another page, I am getting no errors put the info is not either being passed across or displayed I have tried for hours to get this to work with no avail.page 1 is where I input data and page 2 is where it should be displayed.
Could someone point me in a good or right direction, please?
I have now edited my code as given in the help below on the page that is now receiving the info I cannot get it to display.
PAGE1
package com.example.james.visitorapp
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.AlarmClock.EXTRA_MESSAGE
import android.view.View
import android.widget.EditText
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
/** Called when the user taps the Send button */
fun sendMessage(view: View) {
val editText = findViewById<EditText>(R.id.editText)
val editText2 = findViewById<EditText>(R.id.editText2)
val editText3 = findViewById<EditText>(R.id.editText3)
val message1 = editText.text.toString()
val message2 = editText2.text.toString()
val message3 = editText3.text.toString()
val intent = Intent(this, DisplayMessageActivity::class.java).apply {
putExtra(EXTRA_MESSAGE, arrayOf(message1, message2, message3))
}
startActivity(intent)
}
}
receiving page
package com.example.james.visitorapp
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.AlarmClock.EXTRA_MESSAGE
import android.widget.TextView
class DisplayMessageActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_display_message)
// Get the Intent that started this activity and extract the string
val message1 = intent.getStringExtra(EXTRA_MESSAGE)
val message2 = intent.getStringExtra(EXTRA_MESSAGE)
val message3 = intent.getStringExtra(EXTRA_MESSAGE)
// Capture the layout's TextView and set the string as its text
val textView = findViewById<TextView>(R.id.textView).apply {
text = message1
}
val textView2 = findViewById<TextView>(R.id.textView2).apply {
text = message2
}
val textView3 = findViewById<TextView>(R.id.textView3).apply {
text = message3
}
}
}