Senin, 30 Januari 2023

GUI ANDROID STUDIO: LAYOUT

 Pada kesempatan kali ini kita akan membahas bagaimana cara menggunakan Layout dan menggabungkan antara relative dan linierlayout pada Android Studio meenggunakan aplikasi Android Studio

Desain UI


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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Selamat Datang Di Program Sederhana Saya"
android:textStyle="bold"
android:textSize="40dp"
android:layout_marginBottom="50dp"
android:layout_marginTop="20dp"

/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ayo Perkenalkan Diri Anda"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:layout_marginBottom="30dp"
/>
<EditText
android:id="@+id/h"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Silahkan masukkan nama anda: "
android:textSize="18dp"
/>


</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="365dp"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:layout_alignParentTop="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:layout_alignParentRight="true"
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"

/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_alignParentBottom="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"

/>
</RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Jika ada kekurangan mohon dimaafkan:)


GUI ANDROID STUDIO: DESAIN FORM INPUT | GETTEXT DAN SETTEXT

 


Pada kesempatan kali ini kita akan membuat aplikasi form input pada Android Studio dengan menggunakan GetText dan SetText dengan cara yang sederhana.


Berikut untuk file MainActivity.java :

package com.example.rpl1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void Klik(View view) {
EditText getJam = findViewById(R.id.txtJam);
EditText getId = findViewById(R.id.txtId);
EditText getNama = findViewById(R.id.txtNama);
EditText getEmail = findViewById(R.id.txtEmail);
EditText getTgl = findViewById(R.id.txtTanggalLahir);
RadioGroup JK = findViewById(R.id.rdJK);
CheckBox getSlt = findViewById(R.id.cbSilat);
CheckBox getKrt = findViewById(R.id.cbKarate);
TextView setId = findViewById(R.id.lblId);
TextView setNama = findViewById(R.id.lblNama);
TextView setJK = findViewById(R.id.lblJK);
TextView setEmail = findViewById(R.id.lblEmail);
TextView setTanggal = findViewById(R.id.lblTanggal);
TextView setJam = findViewById(R.id.lblJam);
TextView setSlt = findViewById(R.id.lblSlt);
TextView setKrt = findViewById(R.id.lblKarate);


int jk = JK.getCheckedRadioButtonId();
Button Gender = findViewById(jk);
String gender = Gender.getText().toString();

String id = getId.getText().toString();
String name = getNama.getText().toString();
String email = getEmail.getText().toString();
String tgl = getTgl.getText().toString();
String jam = getJam.getText().toString();

String a = "";
if (getSlt.isChecked()){
a+="Silat";
}
String b = "";
if (getKrt.isChecked()){
b+="Karate";
}

setJK.setText(gender);
setId.setText(id);
setNama.setText(name);
setEmail.setText(email);
setTanggal.setText(tgl);
setJam.setText(jam);
setSlt.setText(a);
setKrt.setText(b);
}
}

Berikut untuk file Activity_Main.xml:
<?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=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#5C0063"
android:padding="10dp"
android:text="Form Input"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
app:layout_constraintTop_toBottomOf="@+id/textView" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="JAM PENDAFTARAN"
/>
<EditText
android:id="@+id/txtJam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Time"
android:inputType="time"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="NO.ID"
/>
<EditText
android:id="@+id/txtId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input No ID"
android:inputType="number"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Nama"
/>
<EditText
android:id="@+id/txtNama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input Nama"
android:inputType="text"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Email"
/>
<EditText
android:id="@+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input Email"
android:inputType="textEmailAddress"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Tanggal Lahir"
/>
<EditText
android:id="@+id/txtTanggalLahir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Tanggal Lahir"
android:inputType="date"
/>

<RadioGroup
android:id="@+id/rdJK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Laki-laki"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Perempuan"
/>
</RadioGroup>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"

>
<CheckBox
android:id="@+id/cbSilat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Silat"
android:layout_marginRight="20dp"
/>
<CheckBox
android:id="@+id/cbKarate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Karate"
android:layout_marginRight="20dp"
/>
</LinearLayout>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIMPAN"
android:onClick="Klik"

/>

<TextView
android:id="@+id/lblJam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<TextView
android:id="@+id/lblId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<TextView
android:id="@+id/lblNama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<TextView
android:id="@+id/lblEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<TextView
android:id="@+id/lblTanggal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<TextView
android:id="@+id/lblJK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/lblSlt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Hasil: "
android:layout_marginRight="50dp"
/>
<TextView
android:id="@+id/lblKarate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
/>
<!-- android:text="Hasil: "-->
</LinearLayout>

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Berikut hasil dari desain aplikasi:


                   Jika ada kekurangan mohon dimaafkan:)




GUI ANDROID STUDIO: LAYOUT

  Pada kesempatan kali ini kita akan membahas bagaimana cara menggunakan Layout dan menggabungkan antara relative dan linierlayout pada Andr...