Assalammualaikum wr,wb kali ini saya akan mempost
project UAS saya berbasis aplikasi yang menggunakan eclipse, Aplikasi
yang saya buat adalah penjualan pulsa sehingga memudahkan si penjual untuk
bertransaksi langsung saja tentu langkah pertama adalah membuka eclipse lalu
membuat main activity baru disini saya buat berikut langkah – langkahnya :
Deskripsi Perancangan dan pembuatan
Project :
Pada design ini dibuat 3 Main
Activity :
1. login activity
2. success activity
3. tabhost activity
LANGKAH-LANGKAH
1. Buat main actifvity seperti berikut
menggunakan = a. textview ( username, password)
b. textfield (admin, admin)
c. button (login,tutup)
-->BERIKUT CODINGAN LOGIN
package com.example.penjualanpulsa;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
private String[][] dataUser = {{"ADMIN","ADMIN","Administrator"},
{"user1","password1","Nama User 1"},
{"user2","password2","Nama User 2"}};
private EditText userNameET, passwordET; private final int SUCCESS=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userNameET = (EditText) findViewById(R.id.userNameEditText);
passwordET = (EditText) findViewById(R.id.passwordEditText);
findViewById(R.id.loginButton).setOnClickListener(this);
findViewById(R.id.tutupButton).setOnClickListener(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 v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.loginButton:
int i=0;
boolean success=false;
while ((i<dataUser.length) && (!success)){
if
((userNameET.getText().toString().equals(dataUser[i][0])) &&
(passwordET.getText().toString().equals(dataUser[i][1]))){ success=true;
} else {
i++;
}
}
Intent intent;
if (success){
intent = new Intent(this, SuccessActivity.class); intent.putExtra("namaUser", dataUser[i][2]);
startActivityForResult(intent,SUCCESS);
} else {
userNameET.setError("Username salah");
passwordET.setError("Password salah");
}
break;
case R.id.tutupButton:
System.exit(0);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
switch (requestCode) { case SUCCESS:
userNameET.setText(""); passwordET.setText("");
break;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
private String[][] dataUser = {{"ADMIN","ADMIN","Administrator"},
{"user1","password1","Nama User 1"},
{"user2","password2","Nama User 2"}};
private EditText userNameET, passwordET; private final int SUCCESS=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userNameET = (EditText) findViewById(R.id.userNameEditText);
passwordET = (EditText) findViewById(R.id.passwordEditText);
findViewById(R.id.loginButton).setOnClickListener(this);
findViewById(R.id.tutupButton).setOnClickListener(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 v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.loginButton:
int i=0;
boolean success=false;
while ((i<dataUser.length) && (!success)){
if
((userNameET.getText().toString().equals(dataUser[i][0])) &&
(passwordET.getText().toString().equals(dataUser[i][1]))){ success=true;
} else {
i++;
}
}
Intent intent;
if (success){
intent = new Intent(this, SuccessActivity.class); intent.putExtra("namaUser", dataUser[i][2]);
startActivityForResult(intent,SUCCESS);
} else {
userNameET.setError("Username salah");
passwordET.setError("Password salah");
}
break;
case R.id.tutupButton:
System.exit(0);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
switch (requestCode) { case SUCCESS:
userNameET.setText(""); passwordET.setText("");
break;
}
}
HASIL KERJA SCREENSHOOT
2. buat success_activity
menggunakan listview
-->BERIKUT CODINGAN SUCCESS ACTIVITY
package com.example.penjualanpulsa;
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Intent;
public class SuccessActivity extends Activity {
ListView LV;
String [] Pulsa={"Aplikasi Pulsa","Aplikasi TokenListrik","Aplikasi PaketData"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
LV=(ListView) findViewById(R.id.listView1);
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,Pulsa);
LV.setAdapter(adapter);
LV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
int itemke=arg2;
String itemText=(String) LV.getItemAtPosition(arg2);
Toast.makeText(getApplicationContext(), "text"+itemke, Toast.LENGTH_LONG).show();
if(itemText.equals("Aplikasi Pulsa")){
Intent SeninIntent=new Intent(arg0.getContext(),Pulsa.class);
startActivityForResult(SeninIntent,0);
}else if (itemText.equals("Aplikasi TokenListrik")){
Intent SeninIntent=new Intent(arg0.getContext(),TokenListrik.class);
startActivityForResult(SeninIntent, 0);
}else if (itemText.equals("Aplikasi PaketData")){
Intent SeninIntent=new Intent(arg0.getContext(),PaketData.class);
startActivityForResult(SeninIntent, 0);
}
}}) ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.success, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Intent;
public class SuccessActivity extends Activity {
ListView LV;
String [] Pulsa={"Aplikasi Pulsa","Aplikasi TokenListrik","Aplikasi PaketData"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
LV=(ListView) findViewById(R.id.listView1);
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,Pulsa);
LV.setAdapter(adapter);
LV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
int itemke=arg2;
String itemText=(String) LV.getItemAtPosition(arg2);
Toast.makeText(getApplicationContext(), "text"+itemke, Toast.LENGTH_LONG).show();
if(itemText.equals("Aplikasi Pulsa")){
Intent SeninIntent=new Intent(arg0.getContext(),Pulsa.class);
startActivityForResult(SeninIntent,0);
}else if (itemText.equals("Aplikasi TokenListrik")){
Intent SeninIntent=new Intent(arg0.getContext(),TokenListrik.class);
startActivityForResult(SeninIntent, 0);
}else if (itemText.equals("Aplikasi PaketData")){
Intent SeninIntent=new Intent(arg0.getContext(),PaketData.class);
startActivityForResult(SeninIntent, 0);
}
}}) ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.success, menu);
return true;
}
}
HASIL SCREENSHOOT
3.MEMBUAT TABHOST
A.PULSA.XML
(menggunakan tabhost)
-->BERIKUT CODINGAN PULSA ACTIVITY
package com.example.penjualanpulsa;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.app.TabActivity;
import android.widget.TabHost;
public class Pulsa extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pulsa);
Intent intent;
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
intent = new Intent().setClass(this, Pembayaran.class);
spec = getTabHost().newTabSpec("pembayaran").setIndicator("pembayaran").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Print.class);
spec = getTabHost().newTabSpec("PRINT").setIndicator("PRINT").setContent(intent);
tabHost.addTab(spec);
}}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.app.TabActivity;
import android.widget.TabHost;
public class Pulsa extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pulsa);
Intent intent;
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
intent = new Intent().setClass(this, Pembayaran.class);
spec = getTabHost().newTabSpec("pembayaran").setIndicator("pembayaran").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Print.class);
spec = getTabHost().newTabSpec("PRINT").setIndicator("PRINT").setContent(intent);
tabHost.addTab(spec);
}}
HASIL SCREENSHOOT
B.PEMBAYARAN.XML
MENGGUNAKAN =
- textview (oprator,noHp,,jenis,harga,total)
-radiobutton grup (mentari,telkomsel)
-button (bayar,print)
-->BERIKUT CODINGAN PEMBAYARAN ACTIVITY
package com.example.penjualanpulsa;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.view.View;
import android.content.*;
public class Pembayaran extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
RadioButton rb0;
RadioButton rb1;
EditText edit1,edit2,edit4,edit5;
Button tunghi,plint;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pembayaran);
rb0 = (RadioButton)findViewById(R.id.r1);
rb1 = (RadioButton)findViewById(R.id.r2);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener((OnCheckedChangeListener) this);
edit1=(EditText)findViewById(R.id.oprator);
edit2=(EditText)findViewById(R.id.no);
edit4=(EditText)findViewById(R.id.harga);
edit5=(EditText)findViewById(R.id.total);
tunghi= (Button) findViewById(R.id.button1);
tunghi.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int j=Integer.parseInt(edit4.getText().toString());
int total =j+2500;
edit5.setText(""+total);
}
});
plint= (Button) findViewById(R.id.button2);
plint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String var_nama = edit1.getText().toString();
String var_id = edit2.getText().toString();
String var_banyak = edit4.getText().toString();
String var_lama = edit5.getText().toString();
Intent intent = null;
intent = new Intent(Pembayaran.this,Print.class);
Bundle bundle = new Bundle();
bundle.putString("NO",var_nama);
bundle.putString("OPRATOR",var_id);
bundle.putString("HARGA",var_banyak);
bundle.putString("parse_total",var_lama);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pembayaran, menu);
return true;
}
@Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
if(rb0.isChecked()){
Toast.makeText(this,"you choice mentari",Toast.LENGTH_LONG).show();
edit1.setText("Mentari");
}else {
Toast.makeText(this,"you choice Telkomsel",Toast.LENGTH_LONG).show();
edit1.setText("telkomsel");
}
}
}
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.view.View;
import android.content.*;
public class Pembayaran extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
RadioButton rb0;
RadioButton rb1;
EditText edit1,edit2,edit4,edit5;
Button tunghi,plint;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pembayaran);
rb0 = (RadioButton)findViewById(R.id.r1);
rb1 = (RadioButton)findViewById(R.id.r2);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener((OnCheckedChangeListener) this);
edit1=(EditText)findViewById(R.id.oprator);
edit2=(EditText)findViewById(R.id.no);
edit4=(EditText)findViewById(R.id.harga);
edit5=(EditText)findViewById(R.id.total);
tunghi= (Button) findViewById(R.id.button1);
tunghi.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int j=Integer.parseInt(edit4.getText().toString());
int total =j+2500;
edit5.setText(""+total);
}
});
plint= (Button) findViewById(R.id.button2);
plint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String var_nama = edit1.getText().toString();
String var_id = edit2.getText().toString();
String var_banyak = edit4.getText().toString();
String var_lama = edit5.getText().toString();
Intent intent = null;
intent = new Intent(Pembayaran.this,Print.class);
Bundle bundle = new Bundle();
bundle.putString("NO",var_nama);
bundle.putString("OPRATOR",var_id);
bundle.putString("HARGA",var_banyak);
bundle.putString("parse_total",var_lama);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pembayaran, menu);
return true;
}
@Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
if(rb0.isChecked()){
Toast.makeText(this,"you choice mentari",Toast.LENGTH_LONG).show();
edit1.setText("Mentari");
}else {
Toast.makeText(this,"you choice Telkomsel",Toast.LENGTH_LONG).show();
edit1.setText("telkomsel");
}
}
}
HASIL RUN SCREENSHOOT
C. PRINT.XML
menggunakan = textfiew
-->BERIKUT CODINGAN PRINT ACTIVITY
package com.example.penjualanpulsa;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.view.View;
import android.content.*;
public class Pembayaran extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
RadioButton rb0;
RadioButton rb1;
EditText edit1,edit2,edit4,edit5;
Button tunghi,plint;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pembayaran);
rb0 = (RadioButton)findViewById(R.id.r1);
rb1 = (RadioButton)findViewById(R.id.r2);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener((OnCheckedChangeListener) this);
edit1=(EditText)findViewById(R.id.oprator);
edit2=(EditText)findViewById(R.id.no);
edit4=(EditText)findViewById(R.id.harga);
edit5=(EditText)findViewById(R.id.total);
tunghi= (Button) findViewById(R.id.button1);
tunghi.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int j=Integer.parseInt(edit4.getText().toString());
int total =j+2500;
edit5.setText(""+total);
}
});
plint= (Button) findViewById(R.id.button2);
plint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String var_nama = edit1.getText().toString();
String var_id = edit2.getText().toString();
String var_banyak = edit4.getText().toString();
String var_lama = edit5.getText().toString();
Intent intent = null;
intent = new Intent(Pembayaran.this,Print.class);
Bundle bundle = new Bundle();
bundle.putString("NO",var_nama);
bundle.putString("OPRATOR",var_id);
bundle.putString("HARGA",var_banyak);
bundle.putString("parse_total",var_lama);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pembayaran, menu);
return true;
}
@Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
if(rb0.isChecked()){
Toast.makeText(this,"you choice mentari",Toast.LENGTH_LONG).show();
edit1.setText("Mentari");
}else {
Toast.makeText(this,"you choice Telkomsel",Toast.LENGTH_LONG).show();
edit1.setText("telkomsel");
}
}
}
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.view.View;
import android.content.*;
public class Pembayaran extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
RadioButton rb0;
RadioButton rb1;
EditText edit1,edit2,edit4,edit5;
Button tunghi,plint;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pembayaran);
rb0 = (RadioButton)findViewById(R.id.r1);
rb1 = (RadioButton)findViewById(R.id.r2);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener((OnCheckedChangeListener) this);
edit1=(EditText)findViewById(R.id.oprator);
edit2=(EditText)findViewById(R.id.no);
edit4=(EditText)findViewById(R.id.harga);
edit5=(EditText)findViewById(R.id.total);
tunghi= (Button) findViewById(R.id.button1);
tunghi.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int j=Integer.parseInt(edit4.getText().toString());
int total =j+2500;
edit5.setText(""+total);
}
});
plint= (Button) findViewById(R.id.button2);
plint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String var_nama = edit1.getText().toString();
String var_id = edit2.getText().toString();
String var_banyak = edit4.getText().toString();
String var_lama = edit5.getText().toString();
Intent intent = null;
intent = new Intent(Pembayaran.this,Print.class);
Bundle bundle = new Bundle();
bundle.putString("NO",var_nama);
bundle.putString("OPRATOR",var_id);
bundle.putString("HARGA",var_banyak);
bundle.putString("parse_total",var_lama);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pembayaran, menu);
return true;
}
@Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
if(rb0.isChecked()){
Toast.makeText(this,"you choice mentari",Toast.LENGTH_LONG).show();
edit1.setText("Mentari");
}else {
Toast.makeText(this,"you choice Telkomsel",Toast.LENGTH_LONG).show();
edit1.setText("telkomsel");
}
}
}
HASIL RUN SCREENSHOOT