GUI CheckBox And RadioButton

 Untuk Membuat CheckBox Dan Radio Button Pada Android Studio         Maka Buatlah Codingan berikut Pada 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:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:text="FORM INPUT"
android:textAlignment="center"
android:textSize="30dp"
android:background="@color/purple_500"
android:textColor="@color/white"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="50dp"
android:orientation="vertical"
>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="NO.ID"
app:layout_constraintTop_toTopOf="@+id/txtTime"
android:layout_marginTop="5dp"
/>

<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:text="NAMA"
app:layout_constraintTop_toTopOf="@+id/txtId"
android:layout_marginTop="5dp"
/>

<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:text="EMAIL"
app:layout_constraintTop_toTopOf="@+id/txtNama"
android:layout_marginTop="5dp"
/>

<EditText
android:id="@+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="INPUT EMAIL"
android:inputType="textEmailAddress"
/>

</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hobi"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="260dp"
/>
<LinearLayout
android:id="@+id/lnHobi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="280dp">
<CheckBox
android:id="@+id/chcSilat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Silat"/>


<CheckBox
android:id="@+id/chcKarate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Karate"/>

</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jenis Kelamin"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="330dp"
/>
<RadioGroup
android:id="@+id/rgJk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="350dp"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rdLaki"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Laki-Laki"/>


<RadioButton
android:id="@+id/rdPerempuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Perempuan"/>
</RadioGroup>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIMPAN"
app:layout_constraintTop_toTopOf="@id/rgJk"
android:layout_marginTop="50dp"
android:textSize="20dp"
android:onClick="simpan"
tools:ignore="OnClick" />
<TextView
android:id="@+id/lblId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID"
android:textSize="20dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="480dp"/>

<TextView
android:id="@+id/lblNama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="NAMA"
android:textSize="20dp"
app:layout_constraintTop_toTopOf="@+id/lblId"
android:layout_marginTop="40dp"/>

<TextView
android:id="@+id/lblEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EMAIL"
android:textSize="20dp"
app:layout_constraintTop_toTopOf="@+id/lblNama"
android:layout_marginTop="40dp"/>

<TextView
android:id="@+id/lblHobi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="HOBI"
android:textSize="20dp"
app:layout_constraintTop_toTopOf="@+id/lblEmail"
android:layout_marginTop="40dp"/>


<TextView
android:id="@+id/lblJk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Jenis Kelamin"
android:textSize="20dp"
app:layout_constraintTop_toTopOf="@+id/lblHobi"
android:layout_marginTop="40dp"/>


</androidx.constraintlayout.widget.ConstraintLayout>

Setelah Membuat Code Diatas Untuk Mengaktifkan Tombol Button Agar Saat Kita Click Akan Memunculkan Data Yang Kita Input Maka Buatlah Codingan Berikut Pada 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 simpan(View view) {
//untuk menyimpan data yang di input
EditText Id = findViewById(R.id.txtId);
EditText Nama = findViewById(R.id.txtNama);
EditText Email = findViewById(R.id.txtEmail);
CheckBox Silat = findViewById(R.id.chcSilat);
CheckBox Karate = findViewById(R.id.chcTaekwondo);
RadioGroup Jk = findViewById(R.id.rgJk);

//menyimpan data
TextView setId = findViewById(R.id.lblId);
TextView setNama = findViewById(R.id.lblNama);
TextView setEmail = findViewById(R.id.lblEmail);
TextView setSilat = findViewById(R.id.lblHobi);
TextView setTaekwondo = findViewById(R.id.lblHobi);
TextView setJk = findViewById(R.id.lblJk);

int tId = Integer.parseInt(Id.getText().toString());
String getNama = Nama.getText().toString();
String getEmail = Email.getText().toString();
String getSilat = Silat.getText().toString();
String getTaekwondo = Karate.getText().toString();

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


//menampilkan
setId.setText(Integer.toString(tId));
setNama.setText(getNama);
setEmail.setText(getEmail);
setSilat.setText(getSilat);
setTaekwondo.setText(getTaekwondo);
setJk.setText(gender);

}
                        Setelah Membuat Codingan Diatas Maka Menghasilkan Tampilan Berikut :

Sekian Penjelasan Dari Saya,Saya Ucapkan Terima Kasih.




0 Comments:

Posting Komentar