2. Beri nama aplikasi di Application Name
3. Setelah sukses pembuatan project lalu buka res> layout> activity_main.xml lalu inputkan source code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="HardcodedText" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/Lblnim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="INPUT DATA DIRI"
android:layout_centerHorizontal="true"
android:textSize="18sp" />
<TextView
android:id="@+id/Lblnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Lblnim"
android:layout_marginTop="7dp"
android:text="Nama"
android:textSize="18sp" />
<EditText
android:id="@+id/namafield"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/Lblnama"
android:layout_below="@+id/Lblnim"
android:inputType="text" >
</EditText>
<TextView
android:id="@+id/Lblemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Lblnama"
android:layout_marginTop="15dp"
android:text="E-mail"
android:textSize="18sp" />
<EditText
android:id="@+id/emailfield"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/namafield"
android:layout_toRightOf="@+id/Lblemail"
android:inputType="textEmailAddress" >
</EditText>
<TextView
android:id="@+id/Lbljk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Lblemail"
android:layout_marginTop="15dp"
android:text="Jenis Kelamin"
android:textSize="18sp" />
<RadioGroup
android:id="@+id/jkgroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Lbljk"
android:orientation="horizontal"
android:padding="5dp" >
<RadioButton
android:id="@+id/radiolk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Laki-Laki"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radiopr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Perempuan"
android:textSize="18sp" />
</RadioGroup>
<TextView
android:id="@+id/Lblhobi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/jkgroup"
android:layout_marginTop="7dp"
android:text="Hobi"
android:textSize="18sp" />
<CheckBox
android:id="@+id/CBOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Lblhobi"
android:layout_marginTop="5dp"
android:text="Sholat"
android:textSize="18sp" />
<CheckBox
android:id="@+id/CBTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/CBOne"
android:layout_marginTop="5dp"
android:text="Mengaji"
android:textSize="18sp" />
<CheckBox
android:id="@+id/CBThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/CBTwo"
android:layout_marginTop="5dp"
android:text="Mencuri"
android:textSize="18sp" />
<Button
android:id="@+id/btntampil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/CBThree"
android:layout_marginTop="5dp"
android:text="TAMPILKAN"
android:textSize="18sp" />
<TextView
android:id="@+id/outnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btntampil"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outnama"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outhobi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outemail"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outjk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outhobi"
android:layout_marginTop="5dp"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
4. Buka MainActivity.java dan inputkan source codenya
package com.example.inputdatadiri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainActivity extends Activity implements OnClickListener, OnCheckedChangeListener {
EditText namafield,emailfield;
Button btntampil;
RadioGroup jkgroup;
RadioButton radiolk, radiopr;
CheckBox CBOne, CBTwo, CBThree;
TextView outnama, outemail, outjk, outhobi;
String jk, hobi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailfield = (EditText)findViewById(R.id.emailfield);
namafield = (EditText)findViewById(R.id.namafield);
btntampil = (Button)findViewById(R.id.btntampil);
jkgroup = (RadioGroup)findViewById(R.id.jkgroup);
CBOne = (CheckBox)findViewById(R.id.CBOne);
CBTwo = (CheckBox)findViewById(R.id.CBTwo);
CBThree = (CheckBox)findViewById(R.id.CBThree);
outnama =(TextView)findViewById(R.id.outnama);
outemail =(TextView)findViewById(R.id.outemail);
outhobi = (TextView)findViewById(R.id.outhobi);
outjk = (TextView)findViewById(R.id.outjk);
btntampil.setOnClickListener(this);
jkgroup.setOnCheckedChangeListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View klik) {
// TODO Auto-generated method stub
outnama.setText("Nama Anda : "+namafield.getText());
outemail.setText("Email Anda : "+emailfield.getText());
if (CBOne.isChecked() && CBTwo.isChecked() && CBThree.isChecked()){
outhobi.setText("Hobi Anda : Sholat, Mengaji & Mencuri");
}else if(CBOne.isChecked() && CBTwo.isChecked()){
outhobi.setText("Hobi Anda : Sholat & Mengaji");
}else if(CBOne.isChecked() && CBThree.isChecked()){
outhobi.setText("Hobi Anda : Sholat & Mencuri");
}else if(CBTwo.isChecked() && CBThree.isChecked()){
outhobi.setText("Hobi Anda : Mengaji & Mencuri");
}else if(CBOne.isChecked()){
outhobi.setText("Hobi Anda : Sholat");
}else if(CBTwo.isChecked()){
outhobi.setText("Hobi Anda: Mengaji");
}else if(CBThree.isChecked()){
outhobi.setText("Hobi Anda : Mencuri");
}else{
outhobi.setText("Hobi Anda : ");
}
outjk.setText(jk);
namafield.setText("");
emailfield.setText("");
CBOne.setChecked(false);
CBTwo.setChecked(false);
CBThree.setChecked(false);
jkgroup.clearCheck();
}
@Override
public void onCheckedChanged(RadioGroup group, int check) {
// TODO Auto-generated method stub
if(check==R.id.radiolk){
jk="Jenis Kelamin : Laki-Laki";
}else if(check==R.id.radiopr){
jk="Jenis Kelamin : Perempuan";
}else{
jk="Jenis Kelamin :";
}
}
}
5. Lalu Run
Tampilan input bakal kayak gini
Dan Outputnya begini
Cukup mudah kan, anak paud juga pasti bisa :))
Mungkin cukup sekian dan terimakasih
thx gan
ReplyDeletesangat membantu :D
ReplyDelete