android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
+ <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
--- /dev/null
+package com.example.pittihelloworld
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.widget.TextView
+
+class DisplayMessageActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_display_message)
+
+ // extract message from intent
+ val message = intent.getStringExtra(EXTRA_MESSAGE)
+ findViewById<TextView>(R.id.textView).apply {
+ text = message
+ }
+ }
+}
\ No newline at end of file
package com.example.pittihelloworld
+import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
+import android.view.View
+import android.widget.EditText
+
+const val EXTRA_MESSAGE = "com.example.pittihelloworld.MESSAGE"
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
+
+ fun sendMessage(view: View) {
+ val editText = findViewById<EditText>(R.id.messageText)
+ val message = editText.text.toString()
+ val intent = Intent(this, DisplayMessageActivity::class.java).apply {
+ putExtra(EXTRA_MESSAGE, message)
+ }
+ startActivity(intent)
+ }
}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".DisplayMessageActivity">
+
+ <TextView
+ android:id="@+id/textView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:textColor="@color/colorPrimary"
+ android:textSize="14sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.498"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
android:layout_height="match_parent"
tools:context=".MainActivity">
- <TextView
- android:layout_width="wrap_content"
+ <EditText
+ android:id="@+id/messageText"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
- android:text="Hello Android World!"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ android:ems="10"
+ android:hint="@string/edit_message"
+ android:inputType="textPersonName"
+ app:layout_constraintEnd_toStartOf="@+id/sendButton"
+ app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"/>
+ <Button
+ android:id="@+id/sendButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:onClick="sendMessage"
+ android:text="@string/button_send"
+ app:layout_constraintBaseline_toBaselineOf="@+id/messageText"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintStart_toEndOf="@+id/messageText" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<resources>
<string name="app_name">Pitti Hello World</string>
+ <string name="edit_message">Enter a message</string>
+ <string name="button_send">Send</string>
</resources>
\ No newline at end of file