langsung saja,kali ini saya akan membagikan project pemesanan tiket android.
pertama-tama kita lakukan pembuatan project baru...
terserah jalian...
berikut source codenya..
berdasarkan classnya
#
package com.aristopalaguna.utsb.ticketbox;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
ImageButton pesan;
ImageButton official;
ImageButton info;
ImageButton daftar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
pesan= (ImageButton) findViewById(R.id.imageButton1);
official= (ImageButton) findViewById(R.id.imageButton2);
info= (ImageButton) findViewById(R.id.imageButton4);
official.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context,infoActivity.class);
startActivity(intent);
}
});
official.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(context,webActivity.class);
startActivity(intent);
}
});
pesan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, pesanActivity.class);
startActivity(intent);
}
});
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}}
#package com.aristopalaguna.utsb.ticketbox;
import java.text.SimpleDateFormat;
import java.util.Calendar;
#pesanActivity
import android.os.Bundle;
import android.widget.Button;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class pesanActivity extends MainActivity { protected static final OnDateSetListener datePickerListener = null;
private TextView cHasil;
RadioGroup rg;
RadioButton rb1, rb2,rb3,rb4,rb5,rb6;
public Context activity;
String kota ="";
@SuppressLint("SimpleDateFormat") protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pesantiket);
Calendar c1 = Calendar.getInstance();
Toast.makeText(this, "Copyright(c)2015 -Aristo Palaguna ", Toast.LENGTH_LONG).show();
final CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
Button totaal = (Button) findViewById(R.id.button1);
Button semua = (Button) findViewById(R.id.button2);
Button tmbTutup = (Button) findViewById(R.id.button3);
SimpleDateFormat sdf1 = new SimpleDateFormat("d/M/yy h:m:s a");
String strdate1 = sdf1.format(c1.getTime());
final TextView txtdate1 = (TextView) findViewById(R.id.textView2);
txtdate1.setText(strdate1);
final TextView txtjm1 = (TextView) findViewById(R.id.textView4);
final TextView txtjm2 = (TextView) findViewById(R.id.textView5);
final TextView txtjm3 = (TextView) findViewById(R.id.textView6);
final TextView txtjm14 = (TextView) findViewById(R.id.texttottal);
final TextView txtjm15 = (TextView) findViewById(R.id.textView15);
final TextView txtjumlah = (TextView) findViewById(R.id.textView14);
final TextView txtbank = (TextView) findViewById(R.id.textbank);
final TextView txttanggal = (TextView) findViewById(R.id.ttanggal);
final TextView txttacc = (TextView) findViewById(R.id.texacc);
cHasil = (TextView) findViewById(R.id.texttottal);
final EditText edt1=(EditText)findViewById(R.id.editText1);
final EditText edt2=(EditText)findViewById(R.id.editText2);
final EditText edt3=(EditText)findViewById(R.id.editText3);
final EditText edt11=(EditText)findViewById(R.id.editid);
final EditText edt12=(EditText)findViewById(R.id.etNama);
final EditText edt13=(EditText)findViewById(R.id.etemail);
final EditText edt14=(EditText)findViewById(R.id.etNope);
final EditText edt15=(EditText)findViewById(R.id.etAlamat);
final EditText editbank=(EditText)findViewById(R.id.editbank);
final EditText edtjumlah=(EditText)findViewById(R.id.editText11);
final EditText edtatasnma=(EditText)findViewById(R.id.editatsnama);
final EditText edtac=(EditText)findViewById(R.id.editac);
final DatePicker a=(DatePicker) findViewById(R.id.datePicker1);
rb5 = (RadioButton) findViewById(R.id.rdoJK5);
rb6 = (RadioButton) findViewById(R.id.rdoJK6);
totaal.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
int kon1,kon2,kon3,kon4,kon5,kon6,kon7,kon8,kon9,kon0;
double tmp;
kon1 = (Integer.parseInt(edt1.getText().toString()));
kon2 = (Integer.parseInt(edt2.getText().toString()));
kon3 = (Integer.parseInt(edt3.getText().toString()));
tmp=(250000*kon1)+(300000*kon2)+(500000*kon3);
cHasil.setText("Jumlah Yang harus dibayar adalah "+tmp);
}
});
semua.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
txtjm15.setText("Tanggal pembelian"+txtdate1.getText()+
"\n"+ "Tiket Ungu : " +edt1.getText()+"\n"+
"Tiket geisha: " +edt2.getText()+"\n"
+
"Tiket slank: " +edt3.getText()+"\n"
+
"Nomor identitas Anda " +edt11.getText()+"\n"
+
"Nama Anda " +edt12.getText()+"\n"
+
"Email Anda " +edt13.getText()+"\n"
+
"Nomor HP Anda " +edt14.getText()+"\n"
+
"Alamat Anda " +edt15.getText()+"\n"
+
txtjm14.getText()+"\n"
+
"Jumlah Transfer" +edtjumlah.getText()+"\n"
+
"Rekening Atas Nama" +edtatasnma.getText()+"\n"
+
"Nomor Ac" +edtac.getText()+"\n"
);
}
});
rb5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (rb5.isChecked()){
txtjumlah.setText("Jumlah Transfer");
txttanggal.setText("Tgl.Transfer");
txttacc.setText("No.AC ");
editbank.setVisibility(View.VISIBLE);
txtbank.setVisibility(View.VISIBLE);
}
}
});
rb6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (rb6.isChecked()){
txtjumlah.setText("Jumlah Bayar");
txttanggal.setText("Tgl.Bayar");
txttacc.setText("Nm.Kartu Kredit ");
editbank.setVisibility(View.INVISIBLE);
txtbank.setVisibility(View.INVISIBLE);
}
}
});
checkBox1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (v instanceof CheckBox) {
if (((CheckBox) v).isChecked()) {
txtjm1.setVisibility(View.VISIBLE);;
edt1.setVisibility(View.VISIBLE);
} else {
edt1.setText("0");
txtjm1.setVisibility(View.INVISIBLE);;
edt1.setVisibility(View.INVISIBLE);;
}
}
}
});
checkBox2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (v instanceof CheckBox) {
if (((CheckBox) v).isChecked()) {
txtjm2.setVisibility(View.VISIBLE);;
edt2.setVisibility(View.VISIBLE);
} else {
edt2.setText("0");
txtjm2.setVisibility(View.INVISIBLE);;
edt2.setVisibility(View.INVISIBLE);;
}
}
}
});
checkBox3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (v instanceof CheckBox) {
if (((CheckBox) v).isChecked()) {
txtjm3.setVisibility(View.VISIBLE);;
edt3.setVisibility(View.VISIBLE);
} else {
txtjm3.setVisibility(View.INVISIBLE);;
edt3.setVisibility(View.INVISIBLE);;
edt3.setText("0");
}
}
}
});
}
class Proses_Tutup implements Button.OnClickListener {
public void onClick(View v)
{
finish();;
}
}
@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;
}
}
0 komentar: