Codingan_input_data

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

XML

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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=".MainActivity" >

<TextView

android:id="@+id/Label1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginStart="133dp"

android:layout_marginLeft="133dp"

android:layout_marginTop="96dp"

android:background="#efe"

android:text="@string/masukan_nama_anda"

android:textSize="14sp"

android:textStyle="bold" />

<EditText
android:id="@+id/TxtNama"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/Label1"

android:inputType="none"

android:autofillHints=""

tools:ignore="LabelFor"/>

<Button

android:id="@+id/BtnTampil"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/TxtNama"

android:layout_alignParentStart="true"

android:layout_alignParentLeft="true"

android:layout_centerHorizontal="true"

android:layout_marginStart="152dp"

android:layout_marginLeft="152dp"

android:layout_marginTop="32dp"

android:onClick="TampilNama"

android:text="@string/tampilkan"

tools:ignore="OnClick,unknowId" />

<TextView

android:id="@+id/Label2"

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_below="@+id/BtnTampil"

android:gravity="center"

android:padding="5dp"

android:textSize="20sp"

android:textStyle="bold"

tools:layout_editor_absoluteX="0dp"

tools:layout_editor_absoluteY="171dp" />

</RelativeLayout>

--------------------------------------------------------------------

JAVA

Kepalanya beda

import android.annotation.SuppressLint;

import android.os.Bundle;

import android.view.View;

import android.widget.EditText;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText TextNama;

TextView Hasil;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TextNama= findViewById(R.id.TxtNama);

Hasil= findViewById(R.id.Label2);

}
@SuppressLint("SetTextI18n")

public void TampilNama(View v){

Hasil.setText("Nama Anda: "+TextNama.getText());

---------------------------------------------------------------------

<string name="masukan_nama_anda">INPUT NAMA ANDA</string>

<string name="tampilkan">Tampilkan</string>

You might also like