Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
133 views4 pages

Coding Biodata

The document contains code for an Android app that collects user biographical data through text fields and displays it in an introduction sentence. The layout file defines the user interface elements like text fields for name, birthplace, hobby. The Java code handles populating dropdowns, getting the birthdate from a date picker, and displaying the introduction sentence by concatenating the user's inputs.

Uploaded by

Yoga Aji Pratama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views4 pages

Coding Biodata

The document contains code for an Android app that collects user biographical data through text fields and displays it in an introduction sentence. The layout file defines the user interface elements like text fields for name, birthplace, hobby. The Java code handles populating dropdowns, getting the birthdate from a date picker, and displaying the introduction sentence by concatenating the user's inputs.

Uploaded by

Yoga Aji Pratama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Mainactivity.

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"
android:padding="20dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<EditText
android:id="@+id/edit_namapanjang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nama Panjang"/>

<EditText
android:id="@+id/edit_namapanggilan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nama Panggilan"/>

<Spinner
android:id="@+id/spn_jkelamin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="10dp"></Spinner>

<EditText
android:id="@+id/edit_tempatlahir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Tempat Lahir"/>

<Button
android:id="@+id/btn_tgllahir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tanggal Lahir"/>

<EditText
android:id="@+id/edit_alamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Alamat"/>
<EditText
android:id="@+id/edit_hobi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hobi"/>

<EditText
android:id="@+id/edit_pekerjaan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Pekerjaan"/>

<Button
android:id="@+id/btn_proses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Proses"/>

<TextView
android:id="@+id/txt.kalimatpengenalan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pengenalan Diri by:Yoga aji pratama"/>

</LinearLayout>

</RelativeLayout>

MainActivity.java

package com.yoga.biodatayoga;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class MainActivity extends AppCompatActivity {

EditText namapanjang, namapanggilan, tempatlahir, alamat, hobi, pekerjaan;


Spinner jkelamin;
Button tgllahiir, proses;
TextView pengenalandiri;
private int mTahun, mbulan, mhari;

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

namapanjang = (EditText) findViewById(R.id.edit_namapanjang);


namapanggilan = (EditText) findViewById(R.id.edit_namapanggilan);
tempatlahir = (EditText) findViewById(R.id.edit_tempatlahir);
alamat = (EditText) findViewById(R.id.edit_alamat);
hobi = (EditText) findViewById(R.id.edit_hobi);
pekerjaan = (EditText) findViewById(R.id.edit_pekerjaan);

jkelamin = (Spinner) findViewById(R.id.spn_jkelamin);

tgllahiir = (Button) findViewById(R.id.btn_tgllahir);


proses = (Button) findViewById(R.id.btn_proses);

pengenalandiri = (TextView) findViewById(R.id.txt_kalimatpengenalan);

List<String> listkelamin = new ArrayList<String>();


ListKelamin.add("Laki Laki");
ListKelamin.add("Perempuan");

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,


android.R.layout.simple_spinner_item, listkelamin);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
jkelamin.setAdapter(adapter);

tgllahiir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar cal = Calendar.getInstance();
mTahun = cal.get(Calendar.YEAR);
mbulan = cal.get(Calendar.MONTH);
mTahun = cal.get(Calendar.DAY_OF_MONTH);

DatePickerDialog mDateDialog = new


DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int
dayOfMonth) {
tgllahiir.setText(String.valueOf(year) + "-" +
String.valueOf(month+1) + "-" + String.valueOf(dayOfMonth));

}
}, mTahun, mbulan, mhari);
mDateDialog.setTitle("Pilih Tanggal Lahir");
mDateDialog.show();
}
});

proses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

pengenalandiri.setText("Hai nama gue


"+namapanjang.getText().toString()+", panggil aja "+
namapanggilan.getText().toString()+", lahir di
"+tempatlahir.getText().toString()+", "+
tgllahiir.getText().toString()+", Gue tinggal di
"+alamat.getText().toString()+", Hobi gue "+
hobi.getText().toString()+", Dan gue adalah seorang
"+pekerjaan.getText().toString()+" Nice to meet you :) ");
}
});

}
}

You might also like