Permalink
Browse files

Merge branch 'feature/stringTemplate' into develop

  • Loading branch information...
gonzapico committed Apr 22, 2017
2 parents 6d02be7 + fc8fe32 commit 0c2b1a45780e75667c2d13da740905a99dc70d09
@@ -2,7 +2,8 @@ package xyz.gonzapico.myfirstkotlinapp
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
class HomeActivity : AppCompatActivity() {
@@ -12,17 +13,12 @@ class HomeActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
val tvWelcomeMessage = findViewById(R.id.tvWelcomeMessage) as TextView
val btnShowMessage = findViewById(R.id.btnShowMessage) as Button
val etMessage = findViewById(R.id.etMessage) as EditText
tvWelcomeMessage.setText(resources.getString(R.string.welcomeMessage))
btnShowMessage.setOnClickListener { showToastMessage("Hello ${etMessage.text}") }
showToastMessage("Hello ${tvWelcomeMessage.text}")
}
// Normal use
// fun showToastMessage(message : String) = Toast.makeText(this, message, Toast.LENGTH_LONG).show()
// Assigning value directly
fun showToastMessage(message: String) = Toast.makeText(this, message, Toast.LENGTH_LONG).show()
// Assign to the function the response (it doesn't exists void, you can use Unit instead)
}
@@ -7,14 +7,29 @@
android:layout_height="match_parent"
tools:context="xyz.gonzapico.myfirstkotlinapp.HomeActivity">
<TextView
android:id="@+id/tvWelcomeMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout android:layout_width="368dp"
android:layout_height="495dp" android:orientation="vertical"
tools:layout_editor_absoluteY="8dp" tools:layout_editor_absoluteX="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/addYourMessage"/>
<EditText
android:id="@+id/etMessage"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
<Button android:id="@+id/btnShowMessage" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/show_message"/>
<TextView
android:id="@+id/tvWelcomeMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
@@ -1,4 +1,6 @@
<resources>
<string name="app_name">MyFirstKotlinApp</string>
<string name="welcomeMessage">Hello Kotlin!!!</string>
<string name="addYourMessage">Añade tu texto</string>
<string name="show_message">Muestra el mensaje</string>
</resources>

0 comments on commit 0c2b1a4

Please sign in to comment.