activity_main.xml
<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/labelnim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="Termurah dan enak"
android:layout_centerHorizontal="true"
android:textSize="18sp" />
<TextView
android:id="@+id/labelnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/labelnim"
android:layout_marginTop="7dp"
android:text="Nama"
android:textSize="18sp" />
<EditText
android:id="@+id/fieldnama"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/labelnama"
android:layout_below="@+id/labelnim"
android:inputType="text" >
</EditText>
<TextView
android:id="@+id/labelemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/labelnama"
android:layout_marginTop="15dp"
android:text="Alamat"
android:textSize="18sp" />
<EditText
android:id="@+id/fieldemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fieldnama"
android:layout_toRightOf="@+id/labelemail"
android:inputType="textEmailAddress" >
</EditText>
<TextView
android:id="@+id/labeljk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/labelemail"
android:layout_marginTop="15dp"
android:text="Pakai Minum"
android:textSize="18sp" />
<RadioGroup
android:id="@+id/groupjk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/labeljk"
android:orientation="horizontal"
android:padding="5dp" >
<RadioButton
android:id="@+id/radiolk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pakai"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radiopr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Moh"
android:textSize="18sp" />
</RadioGroup>
<TextView
android:id="@+id/labelkeahlian"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/groupjk"
android:layout_marginTop="7dp"
android:text="Menu"
android:textSize="18sp" />
<CheckBox
android:id="@+id/cekboxjava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/labelkeahlian"
android:layout_marginTop="5dp"
android:text="Soto Ayam"
android:textSize="18sp" />
<CheckBox
android:id="@+id/cekboxnet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cekboxjava"
android:layout_marginTop="5dp"
android:text="Rawon Setannn"
android:textSize="18sp" />
<CheckBox
android:id="@+id/cekboxsa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cekboxnet"
android:layout_marginTop="5dp"
android:text="Iwak Peyek"
android:textSize="18sp" />
<Button
android:id="@+id/tomboltampil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cekboxsa"
android:layout_marginTop="5dp"
android:text="CETAK"
android:textSize="18sp" />
<TextView
android:id="@+id/outputnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tomboltampil"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outputemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outputnama"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outputahli"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outputemail"
android:layout_marginTop="5dp"
android:textSize="18sp" />
<TextView
android:id="@+id/outputjk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/outputahli"
android:layout_marginTop="5dp"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
Tampilan 1
Tampilan 2
Source Code :
package com.example.dodolan;
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 fieldnama,fieldemail;
Button tomboltampil;
RadioGroup groupjk;
RadioButton radiolk, radiopr;
CheckBox cekboxjava, cekboxsa, cekboxnet;
TextView outputnama, outputemail, outputjk, outputahli;
String jk, ahli;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fieldemail = (EditText)findViewById(R.id.fieldemail);
fieldnama = (EditText)findViewById(R.id.fieldnama);
tomboltampil = (Button)findViewById(R.id.tomboltampil);
groupjk = (RadioGroup)findViewById(R.id.groupjk);
cekboxjava = (CheckBox)findViewById(R.id.cekboxjava);
cekboxsa = (CheckBox)findViewById(R.id.cekboxsa);
cekboxnet = (CheckBox)findViewById(R.id.cekboxnet);
outputnama =(TextView)findViewById(R.id.outputnama);
outputemail =(TextView)findViewById(R.id.outputemail);
outputahli = (TextView)findViewById(R.id.outputahli);
outputjk = (TextView)findViewById(R.id.outputjk);
tomboltampil.setOnClickListener(this);
groupjk.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.activity_main, menu);
return true;
}
@Override
public void onClick(View klik) {
// TODO Auto-generated method stub
outputnama.setText("Nama Anda : "+fieldnama.getText());
outputemail.setText("Alamat Anda : "+fieldemail.getText());
if (cekboxjava.isChecked() && cekboxnet.isChecked() && cekboxsa.isChecked()){
outputahli.setText("Hidangan : Soto Ayam, Rawon Setannn & Iwak Peyek");
}else if(cekboxjava.isChecked() && cekboxnet.isChecked()){
outputahli.setText("Hidangan: Soto Ayam & Rawon Setannn");
}else if(cekboxjava.isChecked() && cekboxsa.isChecked()){
outputahli.setText("Hidangan: Soto Ayam & Iwak Peyek");
}else if(cekboxnet.isChecked() && cekboxsa.isChecked()){
outputahli.setText("Hidangan: Rawon Setannn & Iwak Peyek");
}else if(cekboxjava.isChecked()){
outputahli.setText("Hidangan: Soto Ayam");
}else if(cekboxnet.isChecked()){
outputahli.setText("Hidangan: Rawon Setannn");
}else if(cekboxsa.isChecked()){
outputahli.setText("Hidangan: Iwak Peyek");
}else{
outputahli.setText("Hidangan: ");
}
outputjk.setText(jk);
fieldnama.setText("");
fieldemail.setText("");
cekboxjava.setChecked(false);
cekboxsa.setChecked(false);
cekboxnet.setChecked(false);
groupjk.clearCheck();
}
@Override
public void onCheckedChanged(RadioGroup group, int check) {
// TODO Auto-generated method stub
if(check==R.id.radiolk){
jk="Pakai Minum : Pakai ";
}else if(check==R.id.radiopr){
jk="Pakai Minum : Moh";
}else{
jk="Jenis Kelamin :";
}
}
}
Terima kasih
0 Comments