1. 1.Buka Eclipse
2. 2. Buatlah Project baru dengan cara File > New
> Android Aplication Project Silahkan beri nama Aplication Name
RekeningListrik atau kamu ingin membuat dengan nama kamu sendiri juga bisa.
3. 3. Buat lah Layout seperti gambar di atas yaitu
hanya menggunakan TextView, Plain Text, dan Button.
3 4.from login
3 4.from login
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Form
Login"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User
Name" />
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User
Name" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout3"
>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Login"
/>
<Button
android:id="@+id/tutupButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tutup"
/>
</LinearLayout>
</RelativeLayout>
4.
66
5. Pastekan Kode Berikut di MainActivity.java
66
5. Pastekan Kode Berikut di MainActivity.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama
Pelanggan"
/>
<EditText
android:id="@+id/txtPelanggan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipe Meteran" />
<EditText
android:id="@+id/txtTipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meter Bulan Lalu" />
<EditText
android:id="@+id/txtMBL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meter Bulan Ini" />
<EditText
android:id="@+id/txtMBI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/btProses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="KALKULASI" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Pelanggan" />
<EditText
android:id="@+id/txtPelangganOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pemakaian" />
<EditText
android:id="@+id/txtPakai"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tagihan" />
<EditText
android:id="@+id/txtTagihan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
5. 6.Selanjutnya Pastekan Kode berikut di
Activity_main.xml
package com.faisal.rekeninglistrik;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
private EditText
txtPelanggan,txtPelangganOut,txtTipe,txtMBL,txtMBI,txtPakai,txtTagihan;
private Button btProses;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPelanggan = (EditText) findViewById(R.id.txtPelanggan);
txtPelangganOut = (EditText)
findViewById(R.id.txtPelangganOut);
txtTipe = (EditText) findViewById(R.id.txtTipe);
txtMBL = (EditText) findViewById(R.id.txtMBL);
txtMBI = (EditText) findViewById(R.id.txtMBI);
txtPakai = (EditText) findViewById(R.id.txtPakai);
txtTagihan = (EditText) findViewById(R.id.txtTagihan);
btProses = (Button) findViewById(R.id.btProses);
btProses.setOnClickListener(new OnClickListener() {
public void
onClick(View v) {
prosesHasil(v);
}
});
}
public void
prosesHasil(View view){
try{
String
namaOut=String.valueOf(txtPelanggan.getText().toString());
String
tipe=String.valueOf(txtTipe.getText().toString());
Double
mbl=Double.parseDouble(txtMBL.getText().toString());
Double
mbi=Double.parseDouble(txtMBI.getText().toString());
Double pakai =mbi -
mbl;
Double tarif=0.00;
Double beban=0.00;
if
(tipe.equals("R1")){
tarif=100.00;
beban=20000.00;
}
else if
(tipe.equals("R2")){
tarif=200.00;
beban=30000.00;
}
else{
tarif=300.0;
beban=50000.00;
}
Double tagihan =
(pakai * tarif) + beban;
txtPelangganOut.setText(String.valueOf(namaOut));
txtPakai.setText(String.valueOf(pakai));
txtTagihan.setText("Tagihan : " +
tagihan);
}
catch(Exception e){
e.printStackTrace();
}
}
}
6. 7. Slesai.... Klik kanan pada project dan Run As


Tidak ada komentar:
Posting Komentar