KUIS III Pemrograman Mobile
KUIS III Pemrograman Mobile
PEMBIMBING :
Yoyok Heru, ST, MT
Disusun oleh :
2. MainActivity.java
package com.example.mygudang;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.view.Menu;
((ArrayAdapter)ListView01.getAdapter()).notifyDataSetInvalidated();
}
@Override
public boolean onCreateOptionsMenu (Menu menu){
this.menu = menu;
menu.add(0,1,0,"Tambah").setIcon(android.R.drawable.btn_plus);
menu.add(0,2,0,"Refresh").setIcon(android.R.drawable.ic_menu_rotate);
menu.add(0,3,0,"Keluar").setIcon(android.R.drawable.ic_menu_close_clear_ca
ncel);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item){
switch (item.getItemId()){
case 1 :
Intent tambah = new Intent(MainActivity.this,
com.example.mygudang.tambah.class);
startActivity(tambah);
case 2:
return true;
case 3:
Intent exit = new Intent(MainActivity.this, exit.class);
startActivity(exit);
}
return false;
}
3. tambah.java
package com.example.mygudang;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tambah);
dbHelper = new sql1(this);
edkode = (EditText) findViewById(R.id.edAddkode);
edbarang = (EditText) findViewById(R.id.edAddbarang);
edjumlah = (EditText) findViewById(R.id.edAddjumlah);
edharga = (EditText) findViewById(R.id.edAddharga);
btnAddSimpan = (Button) findViewById(R.id.btnAddSimpan);
btnAddSimpan.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
SQLiteDatabase db= dbHelper.getWritableDatabase();
db.execSQL("insert into gudang
(Kode,Nama_barang,Jumlah,Harga) values('"
+ edkode.getText().toString() + "','" +
edbarang.getText().toString()
+ "','" + edjumlah.getText().toString() +
"','"
+ edharga.getText().toString() + "')");
Toast.makeText(getApplicationContext(),
"Berhasil",Toast.LENGTH_LONG).show();
MainActivity.ma.RefreshList();
finish();
}
});
}
}
4. Activity_tambah.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".tambah">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kode :"
android:textSize="20dp">
</TextView>
<EditText
android:id="@+id/edAddkode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
tools:ignore="SpeakableTextPresentCheck">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Barang"
android:textSize="20dp">
</TextView>
<EditText
android:id="@+id/edAddbarang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
tools:ignore="SpeakableTextPresentCheck">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jumlah : "
android:textSize="20dp">
</TextView>
<EditText
android:id="@+id/edAddjumlah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
tools:ignore="SpeakableTextPresentCheck">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Harga : "
android:textSize="20dp">
</TextView>
<EditText
android:id="@+id/edAddharga"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp"
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck">
</EditText>
<Button
android:id="@+id/btnAddSimpan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simpan"
android:textSize="20dp">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="20dp"
</Button>
</LinearLayout>
5. Sql1.java
package com.example.mygudang;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
@Override
public void onCreate(SQLiteDatabase db) {
String sql1 = "create table Gudang( Kode varchar primary key,
Nama_barang text null, " +
" Jumlah integer null, Harga text null);";
Log.d("Data", "onCreate: " + sql1);
db.execSQL(sql1);
sql1 = "INSERT INTO Gudang (Kode, Nama_barang, Jumlah, Harga) " +
"VALUES ('A10', 'Kertas A4', '100', '45000');";
db.execSQL(sql1);
sql1 = "INSERT INTO Gudang (Kode, Nama_barang, Jumlah, Harga) " +
"VALUES ('A11', 'Kertas A5', '10', '35000');";
db.execSQL(sql1);
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
// TODO Auto-generated method stub
}
}
6. Desain
Halaman Beranda
Halaman tambah