text box, text label, button
Displaying a text given by the user using text box, text label, and button
File name: MainActivity.kt
package com.example.displaytext
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
class MainActivity: Activity() {
var mButton: Button? = null
var mEdit: EditText? = null
var mText: TextView? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mButton = findViewByld<View>(R.id.button1) as Button
mButton!!.setOnClickListener {
mEdit = findViewByld<View>(R.id.editText1) as EditText
mText = findViewByld<View>(R.id.textView1) as TextView
mText!!.text = "Hello" + mEdit!!.text.toString() + "!"
}
}
File name: activity_main.xml
<RelativeLayout android layout width="409dp"
android:layout_height="354dp"
xmlns:tools="http://schemas.android.com/tools"
tools:layout editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
tools:ignore="MissingConstraints"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_center Horizontal="true"
android:text="@string/empty"
an
an
an
an
an
ar
android:textAppearance="?android:attr/textAppearanceLarge" ar
android:textColor="#A4C639" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="23dp" android:text="Enter your name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0099FF" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:background="#CCCCCC"
android:ems="10"
android:hint="@string/app_name"
android:inputType="textPersonName"
android:minHeight="48dp">
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" android:background="#0099FF"
android:text="Ok"
android:textColor="#3E2723" />
</RelativeLayout>
File name: strings.xml
<resources> <string name="app_name">App 7</string> <string name="empty" />
</resources>
Comments
Post a Comment