LIST CODING DAN PROGRAM
1. Koding Layout
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#CCCCFF">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/judul"
android:layout_marginTop="50dp"
android:text=" APLIKASI SIMULASI LAPORAN" android:textSize="20dp"
android:layout_centerHorizontal="true" android:textColor="#000066"
android:textStyle="bold" /> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/judul2"
android:text="KEUANGAN PRIBADI BERBASIS" android:textSize="20dp"
android:layout_centerHorizontal="true" android:textColor="#000066"
android:textStyle="bold"
android:layout_below="@id/judul" /> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/judul3"
android:text="ANDROID" android:textSize="20dp"
android:layout_centerHorizontal="true" android:textColor="#000066"
android:textStyle="bold"
android:layout_below="@id/judul2"/>
<ImageView
android:layout_width="140dp" android:layout_height="140dp"
android:background="@drawable/logopolsri" android:id="@+id/imageView"
android:layout_marginTop="25dp"
android:layout_centerHorizontal="true" android:layout_below="@+id/judul3"/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DITA YULIANTI"
android:textColor="#000066" android:textStyle="bold"
android:layout_centerHorizontal="true" android:layout_above="@+id/txtno" android:id="@+id/nama"/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0614 3033 0246"
android:textSize="17dp" android:textColor="#000066" android:textStyle="bold" android:id="@+id/txtno"
android:layout_centerHorizontal="true" android:layout_above="@+id/buttonlogin" android:layout_marginBottom="20dp"/> <Button
android:layout_width="200dp" android:layout_height="50dp" android:text="MASUK"
android:id="@+id/buttonlogin" android:textSize="30dp"
android:background="#02bfbf"
android:layout_centerHorizontal="true" android:textAllCaps="false"
android:layout_alignParentBottom="true" android:layout_marginBottom="70dp"/> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="40dp"
android:background="#CCCCFF">
<ImageView
android:layout_width="50dp" android:layout_height="40dp" android:id="@+id/edkoin"
android:background="@drawable/petiduet" /> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edpemasukkan"
android:layout_toRightOf="@id/edkoin" android:layout_marginLeft="10dp" android:text="Pemasukkan"
android:textAllCaps="false" android:textSize="30dp" android:background="#FF0000" />
<ImageView
android:id="@+id/edkoin2"
android:background="@drawable/duithijau" android:layout_below="@id/edkoin"
android:layout_marginTop="30dp"/> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edpengeluaran"
android:layout_toRightOf="@id/edkoin2" android:layout_marginLeft="10dp"
android:text="Pengeluaran" android:textAllCaps="false" android:textSize="30dp"
android:layout_below="@id/edpemasukkan" android:background="#FFFF00"
android:layout_marginTop="20dp"/> <ImageView
android:layout_width="50dp" android:layout_height="40dp" android:id="@+id/edkoin3"
android:background="@drawable/duitreceh" android:layout_below="@id/edkoin2"
android:layout_marginTop="30dp"/> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edinputtabungan" android:layout_toRightOf="@id/edkoin3" android:layout_marginLeft="10dp"
android:text="Tabungan" android:textAllCaps="false" android:textSize="30dp"
android:layout_below="@id/edpengeluaran" android:background="#33FF00"
android:layout_marginTop="20dp"/> <ImageView
android:layout_width="50dp" android:layout_height="40dp" android:id="@+id/edkoin4"
android:background="@drawable/tangan" android:layout_below="@id/edkoin3" android:layout_marginTop="30dp"/> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edadmin"
android:layout_toRightOf="@id/edkoin4" android:layout_marginLeft="10dp"
android:text="Admin"
android:textAllCaps="false" android:textSize="30dp"
android:layout_below="@id/edinputtabungan" android:background="#3366FF"
android:layout_marginTop="20dp"/> <Button
android:layout_height="100dp" android:id="@+id/edback"
android:background="@drawable/moneybag" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:text=" BACK"
style="?android:attr/borderlessButtonStyle" android:textColor="@android:color/white" android:textSize="25dp"/>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="30dp"
android:background="#CCCCFF">> <ImageView
android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="70dp" android:id="@+id/edduitkertas"
android:background="@drawable/duitkertas"/> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edinputpemasukan"
android:layout_toRightOf="@id/edduitkertas" android:layout_marginLeft="10dp"
android:text="Input Pemasukan" android:layout_marginTop="80dp" android:textAllCaps="false" android:textSize="20dp"
android:background="#dccf14"/> <ImageView
android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/edduitkertas3"
android:background="@drawable/duitkertas" android:layout_below="@id/edduitkertas" android:layout_marginTop="20dp"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edhistoripemasukan"
android:layout_below="@id/edinputpemasukan" android:layout_marginLeft="10dp"
android:text="History Pemasukan" android:textAllCaps="false" android:textSize="20dp"
android:layout_marginTop="25dp"
android:layout_toRightOf="@+id/edduitkertas3" android:background="#29d726"/>
<Button
android:layout_height="100dp" android:id="@+id/btnMenuPemasukan" android:background="@drawable/moneybag" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text=" MENU"
android:layout_marginBottom="30dp"
style="?android:attr/borderlessButtonStyle" android:textColor="@android:color/white" android:textSize="25dp"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="30dp"
android:background="#CCCCFF">> <ImageView
android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="70dp" android:id="@+id/edduitkertas"
android:background="@drawable/duitkertas"/> <Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edinputpengeluaran"
android:layout_toRightOf="@id/edduitkertas" android:layout_marginLeft="10dp"
android:text="Input Pengeluaran" android:textAllCaps="false" android:layout_marginTop="80dp" android:textSize="20dp"
android:background="#dccf14"/>
<ImageView
android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/edduitkertas3"
android:background="@drawable/duitkertas" android:layout_below="@id/edduitkertas" android:layout_marginTop="20dp"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edhistoripengeluaran"
android:layout_below="@id/edinputpengeluaran" android:layout_marginLeft="10dp"
android:text="History Pengeluaran" android:textAllCaps="false"
android:textSize="20dp"
android:layout_marginTop="25dp"
android:background="#29d726"/> <Button
android:layout_width="120dp" android:layout_height="100dp"
android:id="@+id/btnMenuPengeluaran" android:background="@drawable/moneybag" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="30dp" android:text=" MENU"
style="?android:attr/borderlessButtonStyle" android:textColor="@android:color/white" android:textSize="25dp"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="50dp"
android:background="#CCCCFF">> <TextView
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark" android:id="@+id/textView"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp"
android:id="@+id/txtLaporan" android:padding="20dp"
android:background="@android:color/white" android:layout_alignParentTop="true" android:layout_alignLeft="@+id/textView" android:layout_alignStart="@+id/textView" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="30dp"
android:paddingTop="50dp" android:background="#CCCCFF">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Keterangan Admin"
android:layout_centerHorizontal="true" android:textSize="25dp"
/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Nama : Dita Yulianti" android:textSize="18dp"
android:layout_marginTop="50dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="NIM : 0614 3033 0246" android:textSize="18dp"
android:layout_marginTop="80dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Kelas : 6 TA" android:textSize="18dp"
android:layout_marginTop="110dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Jurusan : Teknik Elektro" android:textSize="18dp"
android:layout_marginTop="140dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Prodi : T. Telekomunikasi" android:textSize="18dp"
android:layout_marginTop="170dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Pembimbing 1 : Ir. Ali Nurdin, M.T." android:textSize="18dp"
android:layout_marginTop="200dp" android:textColor="#333333"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Pembimbing 2 : Sarjana, S.T., M.Kom" android:textSize="18dp"
android:layout_marginTop="230dp" android:textColor="#333333"/> <Button
android:layout_width="120dp" android:layout_height="100dp" android:id="@+id/btnAdmin"
android:text=" OK"
style="?android:attr/borderlessButtonStyle" android:textColor="@android:color/white" android:layout_alignParentBottom="true" android:layout_marginBottom="30dp" android:textSize="35dp"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="40dp">
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pemasukan"
android:layout_marginTop="80dp"/> <EditText
android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number"
android:id="@+id/inputpemasukkan"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Keterangan"/> <EditText
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edketerangan"/> <Button
android:layout_width="100dp" android:layout_height="50dp" android:id="@+id/btnsimpan" android:layout_gravity="right" android:text="Simpan"
android:textAllCaps="false"
android:layout_marginTop="20dp"/> </LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linear"
android:orientation="horizontal" android:paddingLeft="5dp"
android:paddingRight="5dp" android:paddingTop="10dp" android:paddingBottom="10dp"
android:background="@color/colorPrimary"> <TextView
android:layout_width="80dp"
android:layout_height="wrap_content" android:text="Tanggal"
android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"
/> <TextView
android:layout_width="100dp"
android:layout_height="wrap_content" android:text="Uang Masuk"
android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Keterangan"
android:textColor="@android:color/white" android:textSize="15dp"
android:textStyle="bold"/> </LinearLayout>
<ListView
android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/linear" android:layout_above="@+id/footer" android:id="@+id/lvPemasukan" /> <LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/footer"
android:layout_alignParentBottom="true" android:paddingLeft="5dp"
android:paddingRight="5dp" android:paddingTop="10dp" android:paddingBottom="10dp"
android:background="@color/colorPrimary"> <TextView
android:layout_width="80dp"
android:layout_height="wrap_content" android:text="Total :"
android:textSize="15dp"
/> <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""
android:id="@+id/txtTotalUang" android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"/>
</LinearLayout> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="40dp">
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pengeluaran"
android:layout_marginTop="80dp"/> <EditText
android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number"
android:id="@+id/inputpengeluaran"/> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:text="Keterangan"/> <EditText
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edketerangan"/> <Button
android:layout_width="100dp" android:layout_height="50dp" android:id="@+id/btnsimpan" android:layout_marginTop="20dp" android:layout_gravity="right" android:text="Simpan"
android:textAllCaps="false" />
</LinearLayout> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linear"
android:orientation="horizontal" android:paddingLeft="5dp"
android:paddingRight="5dp" android:paddingTop="10dp" android:paddingBottom="10dp"
android:background="@color/colorPrimary"> <TextView
android:layout_width="80dp"
android:layout_height="wrap_content" android:text="Tanggal"
android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"
/> <TextView
android:layout_width="100dp"
android:layout_height="wrap_content" android:text="Uang Keluar"
android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Keterangan"
android:textColor="@android:color/white" android:textSize="15dp"
android:textStyle="bold"/> </LinearLayout>
<ListView
android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/linear" android:layout_above="@+id/footer" android:id="@+id/lvPengeluaran" /> <LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/footer"
android:layout_alignParentBottom="true" android:paddingLeft="5dp"
android:paddingRight="5dp" android:paddingTop="10dp" android:paddingBottom="10dp"
android:background="@color/colorPrimary"> <TextView
android:layout_width="80dp"
android:text="Total :" android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"
/> <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""
android:id="@+id/txtTotalUang" android:textSize="15dp"
android:textColor="@android:color/white" android:textStyle="bold"/>
</LinearLayout> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content" android:id="@+id/rowTanggal"
android:text="1"
android:padding="5dp"/> <TextView
android:layout_width="100dp"
android:layout_height="wrap_content" android:text="500000000"
android:id="@+id/rowUang" android:padding="5dp"/> <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Nemu dijalan"
android:id="@+id/rowKeterangan" android:padding="5dp"/>
</LinearLayout>
2. Program
package com.example.dita.projectkeuanganpribadi;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity extends AppCompatActivity { Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLogin = (Button)findViewById(R.id.buttonlogin);
btnLogin.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this, Activitymenu.class);
startActivity(intent); }
}); }
}
public class Activitymenu extends AppCompatActivity { Button btnpemasukan;
Button btnpengeluaran; Button btnInputTabungan; Button btnAdmin;
Button btnback;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
btnpemasukan = (Button)findViewById(R.id.edpemasukkan); btnpengeluaran=(Button)findViewById(R.id.edpengeluaran); btnInputTabungan = (Button)
findViewById(R.id.edinputtabungan);
btnAdmin = (Button) findViewById(R.id.edadmin); btnback = (Button)findViewById(R.id.edback);
btnpemasukan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Activitymenu.this, Activitymenupemasukan.class);
startActivity(intent);
} });
btnpengeluaran.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Activitymenu.this, Activitymenupengeluaran.class);
});
btnInputTabungan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Activitymenu.this, LaporanTabungandanKerugian.class);
startActivity(intent); }
});
btnAdmin.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Intent intent = new Intent(Activitymenu.this, ActivityInputAdmin.class);
startActivity(intent); }
});
btnback.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { finish();
} });
} }
public class Activitymenupemasukan extends AppCompatActivity { Button btnMenuInputPemasukan;
Button btnMenuHistoryPemasukan; Button btnMenuPemasukan;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.menupemasukan); btnMenuInputPemasukan = (Button)
findViewById(R.id.edinputpemasukan);
btnMenuHistoryPemasukan = (Button) findViewById(R.id.edhistoripemasukan); btnMenuPemasukan=
(Button)findViewById(R.id.btnMenuPemasukan);
btnMenuInputPemasukan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent = new
Intent(Activitymenupemasukan.this, ActivityInputPemasukan.class);
startActivity(intent); }
btnMenuHistoryPemasukan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent = new
Intent(Activitymenupemasukan.this, ActivityHistoryPemasukan.class);
startActivity(intent); }
});
btnMenuPemasukan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { finish();
} });
} }
public class Activitymenupengeluaran extends AppCompatActivity { Button btnMenuInputpengeluaran;
Button btnMenuHistorypengeluaran; Button btnMenuPengeluaran;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.menupengeluaran); btnMenuInputpengeluaran = (Button)
findViewById(R.id.edinputpengeluaran);
btnMenuHistorypengeluaran = (Button) findViewById(R.id.edhistoripengeluaran); btnMenuPengeluaran=
(Button)findViewById(R.id.btnMenuPengeluaran);
btnMenuInputpengeluaran.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent = new
Intent(Activitymenupengeluaran.this, ActivityInputPengeluaran.class);
startActivity(intent); }
});
btnMenuHistorypengeluaran.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent = new
} });
btnMenuPengeluaran.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { finish();
onBackPressed(); }
}); }
}
public class LaporanTabungandanKerugian extends AppCompatActivity {
TextView txtlaporan; SelectAdaptor ambildata; SQLiteDatabase db;
MenuCustom[] data; Integer totalpemasukan; Integer totalpengeluaran; Integer totalakhir;
DatabaseHelper dbKeuangan;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menutabungandankerugian); txtlaporan=(TextView)findViewById(R.id.txtLaporan);
dbKeuangan= new
DatabaseHelper(LaporanTabungandanKerugian.this); db = dbKeuangan.getReadableDatabase();
ambildata=new
SelectAdaptor(LaporanTabungandanKerugian.this); //sama saja seperti di atas
Cursor c = ambildata.ambilDataIncome(db); //cursor untuk menampung data dari database dan c adalah namanya / eksekusi ambilDataIncome
data = new MenuCustom[c.getCount()]; // totalpemasukan=0;
if (c.getCount()!=0){ if (c.moveToFirst()){ do {
String pemasukan = c.getString(1); Integer
intPemasukan=Integer.valueOf(pemasukan);
totalpemasukan = totalpemasukan + intPemasukan;
}while (c.moveToNext()); }
ambildata=new
SelectAdaptor(LaporanTabungandanKerugian.this); Cursor c2 = ambildata.ambilDataOutcome(db); data = new MenuCustom[c2.getCount()]; // totalpengeluaran=0;
if (c2.getCount()!=0){ if (c2.moveToFirst()){ do {
String pengeluaran = c2.getString(1); Integer
intPengeluaran=Integer.valueOf(pengeluaran);
totalpengeluaran = totalpengeluaran + intPengeluaran;
}while (c2.moveToNext()); }
}
totalakhir=totalpemasukan-totalpengeluaran; if (totalakhir<0){
txtlaporan.setText("Anda mengalami kerugian sebesar Rp." + totalakhir);
}else{
txtlaporan.setText("Anda mempunyai total tabungan sebesar Rp." + totalakhir);
}
} }
public class ActivityInputAdmin extends AppCompatActivity { Button btnOKUbahAdmin;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.tampilanadmin);
btnOKUbahAdmin= (Button)findViewById(R.id.btnAdmin);
btnOKUbahAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent=new
Intent(ActivityInputAdmin.this, Activitymenu.class); startActivity(intent);
} });
btnOKUbahAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { finish();
} });
public class ActivityInputPemasukan extends AppCompatActivity { EditText inputpemasukan;
EditText inputketerangan; Button btnsimpan;
public static int edit = 0;
public static String uang, keterangan, tanggal;
DatabaseHelper dbKeuangan; SQLiteDatabase db;
@Override
protected void onPause() { super.onPause();
edit=0; }
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.inputpemasukan); inputketerangan =
(EditText)findViewById(R.id.edketerangan); inputpemasukan =
(EditText)findViewById(R.id.inputpemasukkan);
btnsimpan = (Button)findViewById(R.id.btnsimpan);
if (edit == 1){
inputpemasukan.setText(uang);
inputketerangan.setText(keterangan); }
dbKeuangan=new
DatabaseHelper(ActivityInputPemasukan.this); db=dbKeuangan.getReadableDatabase(); dbKeuangan.onCreate(db);
btnsimpan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { if (edit==1){
Integer pemasukan; String ket, uang;
uang= inputpemasukan.getText().toString(); ket = inputketerangan.getText().toString(); if (uang.equals("")|| ket.equals("")){
Toast.makeText(getApplicationContext(), "Data Harus Diisi", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "Berhasil menyimpan", Toast.LENGTH_LONG).show();
Intent intent = new Intent(ActivityInputPemasukan.this,
ActivityHistoryPemasukan.class);
startActivity(intent); finish();
} }else {
Integer pemasukan; String ket, uang;
uang = inputpemasukan.getText().toString(); ket = inputketerangan.getText().toString(); if (uang.equals("") || ket.equals("")){ Toast.makeText(getApplicationContext(), "Data Harus Diisi", Toast.LENGTH_LONG).show();
}else {
pemasukan=Integer.valueOf(uang); dbKeuangan.insertPendapatan(db, pemasukan, ket);
Toast.makeText(getApplicationContext(), "Berhasil menyimpan", Toast.LENGTH_LONG).show();
Intent intent = new Intent(ActivityInputPemasukan.this,
ActivityHistoryPemasukan.class);
startActivity(intent); finish();
} } } }); }
}
public class ActivityHistoryPemasukan extends AppCompatActivity {
ListView listPemasukan; TextView txtTotal;
AlertDialog.Builder dialog; MenuCustom[] data;
DatabaseHelper dbKeuangan; SQLiteDatabase db;
SelectAdaptor ambildata; Integer total
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.historipemasukan);
listPemasukan=(ListView)findViewById(R.id.lvPemasukan); txtTotal=(TextView)findViewById(R.id.txtTotalUang);
dbKeuangan = new
ambilData();
listPemasukan.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) { MenuCustom getMenu=data[position]; final String getUang=getMenu.uang;
final String getTanggal=getMenu.tanggal;
final String getKeterangan=getMenu.keterangan; final CharSequence[] dialogitem = {"Edit", "Delete"};
dialog = new
AlertDialog.Builder(ActivityHistoryPemasukan.this); dialog.setCancelable(true);
dialog.setTitle("Pilih salah satu"); dialog.setItems(dialogitem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub switch (which) {
case 0:
ActivityInputPemasukan.keterangan=getKeterangan;
ActivityInputPemasukan.tanggal=getTanggal;
ActivityInputPemasukan.uang=getUang;
ActivityInputPemasukan.edit=1; finish();
Intent intent = new Intent(ActivityHistoryPemasukan.this,
ActivityInputPemasukan.class);
startActivity(intent); break;
case 1:
db.delete(DatabaseHelper.TABLE_PENDAPATAN,
DatabaseHelper.KEY_TANGGAL + " = '" + getTanggal + "';",null); ambilData();
break; }
} }).show(); return false; }
}); }
SelectAdaptor(ActivityHistoryPemasukan.this); Cursor c = ambildata.ambilDataIncome(db); data = new MenuCustom[c.getCount()]; total=0;
if (c.getCount()!=0){ if (c.moveToFirst()){ do {
String pemasukan = c.getString(1); String ket = c.getString(2);
String tgl = c.getString(3); Integer intPemasukan=Integer.valueOf(pemasukan); total = total + intPemasukan;
data[c.getPosition()]=new MenuCustom(tgl,pemasukan,ket);
}while (c.moveToNext()); MenuCustomAdapter adapter=new
MenuCustomAdapter(ActivityHistoryPemasukan.this, R.layout.row_list, data
listPemasukan.setAdapter(adapter);
txtTotal.setText("Rp. "+String.valueOf(total)); }
} } }
public class ActivityInputPengeluaran extends AppCompatActivity {
EditText inputpengeluaran; EditText edketerangan; Button btnsimpan;
DatabaseHelper dbKeuangan; SQLiteDatabase db;
public static int edit = 0;
public static String uang, keterangan, tanggal;
@Override
protected void onPause() { super.onPause();
edit=0; }
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inputpengeluaran); inputpengeluaran =
(EditText)findViewById(R.id.inputpengeluaran);
edketerangan=(EditText)findViewById(R.id.edketerangan); btnsimpan = (Button)findViewById(R.id.btnsimpan);
dbKeuangan=new
if (edit==1){
inputpengeluaran.setText(uang); edketerangan.setText(keterangan); }
btnsimpan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { if(edit==1) {
Integer pengeluaran; String keterangan, uang;
uang=inputpengeluaran.getText().toString(); keterangan =
edketerangan.getText().toString();
if (uang.equals("") || keterangan.equals("")) {
Toast.makeText(getApplicationContext(), "Data Harus Diisi", Toast.LENGTH_LONG).show();
} else {
pengeluaran = Integer.valueOf(uang); dbKeuangan.updatePengeluaran(db, pengeluaran, keterangan, tanggal);
Toast.makeText(ActivityInputPengeluaran.this, "Berhasil menyimpan", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ActivityInputPengeluaran.this,
ActivityHistoryPengeluaran.class);
startActivity(intent); finish();
} }else {
Integer pengeluaran; String keterangan, uang;
uang=inputpengeluaran.getText().toString(); keterangan =
edketerangan.getText().toString();
if (uang.equals("") || keterangan.equals("")){
Toast.makeText(getApplicationContext(), "Data Harus Diisi", Toast.LENGTH_LONG).show();
}else {
pengeluaran = Integer.valueOf(uang); dbKeuangan.insertPengeluaran(db, pengeluaran, keterangan);
Toast.makeText(ActivityInputPengeluaran.this, "Berhasil menyimpan", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ActivityInputPengeluaran.this,
ActivityHistoryPengeluaran.class);
startActivity(intent); finish();
} } }); }
}
public class ActivityHistoryPengeluaran extends AppCompatActivity {
ListView listPengeluaran; TextView txtTotal;
MenuCustom[]data;
DatabaseHelper dbKeuangan; SQLiteDatabase db;
SelectAdaptor ambildata; AlertDialog.Builder dialog;
public static Integer totalpengeluaran;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.historipengeluaran);
listPengeluaran=(ListView)findViewById(R.id.lvPengeluaran); txtTotal=(TextView)findViewById(R.id.txtTotalUang);
dbKeuangan= new
DatabaseHelper(ActivityHistoryPengeluaran.this); db =dbKeuangan.getReadableDatabase();
ambildata();
listPengeluaran.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) { MenuCustom getMenu=data[position]; final String getUang=getMenu.uang;
final String getTanggal=getMenu.tanggal;
final String getKeterangan=getMenu.keterangan; final CharSequence[] dialogitem = {"Edit", "Delete"};
dialog = new
AlertDialog.Builder(ActivityHistoryPengeluaran.this); dialog.setCancelable(true);
dialog.setTitle("Pilih salah satu"); dialog.setItems(dialogitem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityInputPengeluaran.keterangan=getKeterangan;
ActivityInputPengeluaran.tanggal=getTanggal;
ActivityInputPengeluaran.uang=getUang;
ActivityInputPengeluaran.edit=1; finish();
Intent intent = new Intent(ActivityHistoryPengeluaran.this,
ActivityInputPengeluaran.class);
startActivity(intent); break;
case 1:
db.delete(DatabaseHelper.TABLE_PENDAPATAN,
DatabaseHelper.KEY_TANGGAL + " = '" + getTanggal + "';",null); ambildata();
break; }
} }).show(); return false; }
}); }
public void ambildata(){ ambildata=new
SelectAdaptor(ActivityHistoryPengeluaran.this); Cursor c = ambildata.ambilDataOutcome(db); data = new MenuCustom[c.getCount()];
totalpengeluaran=0; if (c.getCount()!=0){ if (c.moveToFirst()){ do {
String pengeluaran = c.getString(1); String ket = c.getString(2);
String tgl = c.getString(3); Integer
intPengeluaran=Integer.valueOf(pengeluaran);
totalpengeluaran = totalpengeluaran + intPengeluaran;
data[c.getPosition()]=new MenuCustom(tgl,pengeluaran,ket);
}while (c.moveToNext()); MenuCustomAdapter adapter=new MenuCustomAdapter(ActivityHistoryPengeluaran.this, R.layout.row_list, data);
listPengeluaran.setAdapter(adapter); txtTotal.setText("Rp.
"+String.valueOf(totalpengeluaran)); }
public class DatabaseHelper extends SQLiteOpenHelper { public static String NAMA_DATABASE ="Keuangan";
public static String TABLE_PENDAPATAN="Tabelpendapatan"; public static String TABLE_PENGELUARAN="Tabelpengeluaran"; public static String KEY_PENDAPATAN="pendapatan";
public static String KEY_PENGELUARAN="pengeluaran"; public static String KEY_TANGGAL="tanggal";
public static String KEY_KETERANGAN="keterangan";
public DatabaseHelper(Context context){ super(context, NAMA_DATABASE, null, 1); }
private static final String CREATE_PENDAPATAN = "CREATE TABLE IF NOT EXISTS " + TABLE_PENDAPATAN
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_PENDAPATAN + " INTEGER,"
+ KEY_KETERANGAN + " TEXT," + KEY_TANGGAL + " DATETIME)";
private static final String CREATE_PENGELUARAN = "CREATE TABLE IF NOT EXISTS " + TABLE_PENGELUARAN
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_PENGELUARAN + " INTEGER,"
+ KEY_KETERANGAN + " TEXT," + KEY_TANGGAL + " DATETIME)";
public void insertPendapatan(SQLiteDatabase db, Integer pendapatan, String keterangan){
ContentValues cv= new ContentValues(); cv.put(KEY_PENDAPATAN, pendapatan); cv.put(KEY_KETERANGAN, keterangan); cv.put(KEY_TANGGAL, getDateTime()); db.insert(TABLE_PENDAPATAN, null, cv); }
private String getDateTime(){
SimpleDateFormat dateFormat = new
SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault()); Date date = new Date();
return dateFormat.format(date); }
public void insertPengeluaran(SQLiteDatabase db,Integer pengeluaran, String keterangan){
ContentValues cv= new ContentValues(); cv.put(KEY_PENGELUARAN, pengeluaran); cv.put(KEY_KETERANGAN, keterangan); cv.put(KEY_TANGGAL, getDateTime()); db.insert(TABLE_PENGELUARAN, null, cv);
}
public void updatePendapatan(SQLiteDatabase db,Integer pendapatan, String keterangan, String tanggal){
cv.put(KEY_PENDAPATAN, pendapatan); cv.put(KEY_KETERANGAN, keterangan); cv.put(KEY_TANGGAL, tanggal);
db.update(TABLE_PENDAPATAN, cv, KEY_TANGGAL + " = '" + tanggal + "';", null);
}
public void updatePengeluaran(SQLiteDatabase db,Integer pengeluaran, String keterangan, String tanggal){
ContentValues cv=new ContentValues(); cv.put(KEY_PENGELUARAN, pengeluaran); cv.put(KEY_KETERANGAN, keterangan); cv.put(KEY_TANGGAL, tanggal);
db.update(TABLE_PENGELUARAN, cv, KEY_TANGGAL + " = '" + tanggal + "';", null);
}
@Override
public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_PENDAPATAN);
db.execSQL(CREATE_PENGELUARAN); }
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} }
public class SelectAdaptor { Context context;
DatabaseHelper dbUser; SQLiteDatabase db;
public SelectAdaptor (Context c){ context = c;
}
public SelectAdaptor open(){
dbUser = new DatabaseHelper(context); db = dbUser.getWritableDatabase(); return this;
}
public Cursor ambilDataIncome(SQLiteDatabase db){ open();
Cursor c = db.rawQuery("SELECT * FROM "+ DatabaseHelper.TABLE_PENDAPATAN,null);
return c; }
public Cursor ambilDataOutcome(SQLiteDatabase db){ open();
return c; }
}
public class MenuCustom {
public String uang, keterangan, tanggal;
public MenuCustom(String tanggal, String uang, String keterangan){
this.tanggal=tanggal; this.uang=uang;
this.keterangan=keterangan; }
}
public class MenuCustomAdapter extends ArrayAdapter<MenuCustom> {
Context context; int resource; MenuCustom[] data;
public MenuCustomAdapter(Context context, int resource, MenuCustom[] data) {
super(context, resource, data); this.context=context;
this.resource=resource; this.data=data;
}
class MenuHolder{ TextView tanggal; TextView uang;
TextView keterangan; }
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row= convertView; MenuHolder holder; if (row==null){
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row=inflater.inflate(resource, parent, false); holder=new MenuHolder();
holder.tanggal =
(TextView)row.findViewById(R.id.rowTanggal); holder.uang =
(TextView)row.findViewById(R.id.rowUang); holder.keterangan =
(TextView)row.findViewById(R.id.rowKeterangan); row.setTag(holder);
holder=(MenuHolder)row.getTag(); }
MenuCustom menu = data[position]; holder.tanggal.setText(menu.tanggal); holder.uang.setText("Rp. "+menu.uang); holder.keterangan.setText(menu.keterangan);
return row; }