Dokumentasi Latihan Mandiri 1 Pemprograman Mobile 2 DISUSUN OLEH Nico Fernades ( A22.2019.02734 ) UNIVERSITAS DIAN NUSWANTORO FAKULTAS ILMU KOMPUTER D-III TEKNIK INFORMATIKA 1. Hasil Akhir 2. Java 3. package com.nicofrnds02734.myapplication; import import import import import androidx.annotation.NonNull; androidx.appcompat.app.AppCompatActivity; androidx.recyclerview.widget.DefaultItemAnimator; androidx.recyclerview.widget.LinearLayoutManager; androidx.recyclerview.widget.RecyclerView; import import import import import import import import import android.content.Intent; android.os.Bundle; android.text.InputType; android.view.View; android.widget.Button; android.widget.EditText; android.widget.LinearLayout; android.widget.RelativeLayout; android.widget.TextView; public class MainActivity extends AppCompatActivity { Button btn_tambah; public static MainActivity ma; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_tambah = findViewById(R.id.btn_tambah); btn_tambah.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //kode TextView tvkode = new TextView(MainActivity.this); tvkode.setText("Kode Barang :"); tvkode.setTextColor(getResources().getColor(R.color.birutua)); EditText edkode = new EditText(MainActivity.this); edkode.setHint("Masukan Kode Barang"); //nama TextView tvnama = new TextView(MainActivity.this); tvnama.setText("Nama Barang :"); tvnama.setTextColor(getResources().getColor(R.color.birutua)); EditText ednama = new EditText(MainActivity.this); ednama.setHint("Masukan Nama Barang"); //satuan TextView tvsatuan = new TextView(MainActivity.this); tvsatuan.setText("Satuan :"); tvsatuan.setTextColor(getResources().getColor(R.color.birutua) ); EditText edsatuan = new EditText(MainActivity.this); edsatuan.setInputType(InputType.TYPE_CLASS_NUMBER); edsatuan.setHint("0"); //jumlah TextView tvjumlah = new TextView(MainActivity.this); tvjumlah.setText("Jumlah :"); tvjumlah.setTextColor(getResources().getColor(R.color.birutua) ); EditText edjumlah = new EditText(MainActivity.this); edjumlah.setInputType(InputType.TYPE_CLASS_NUMBER); edjumlah.setHint("0"); //harga TextView tvharga = new TextView(MainActivity.this); tvharga.setText("Harga :"); tvharga.setTextColor(getResources().getColor(R.color.birutua)) ; EditText edharga = new EditText(MainActivity.this); edharga.setInputType(InputType.TYPE_CLASS_NUMBER); edharga.setHint("Rp ..."); Button button1 = new Button(MainActivity.this); button1.setBackgroundColor(getResources().getColor(R.color.bir umuda)); button1.setTextColor(getResources().getColor(R.color.putih)); button1.setText("Tambah"); LinearLayout linearLayout = new LinearLayout(MainActivity.this); linearLayout.setOrientation(linearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(48, 150, 48, 0); linearLayout.addView(tvkode); linearLayout.addView(edkode); linearLayout.addView(tvnama); linearLayout.addView(ednama); linearLayout.addView(tvsatuan); linearLayout.addView(edsatuan); linearLayout.addView(tvjumlah); linearLayout.addView(edjumlah); linearLayout.addView(tvharga); linearLayout.addView(edharga); linearLayout.addView(button1); setContentView(linearLayout, layoutParams); } }); ma = this; } } 4. Layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <androidx.cardview.widget.CardView android:id="@+id/cardheader" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/gmbr" android:layout_width="60px" android:layout_height="60px" android:layout_marginRight="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="15dp" android:layout_alignParentLeft="true" android:layout_marginBottom="15dp" android:src="@drawable/back"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_toRightOf="@+id/gmbr" android:fontFamily="@font/ubuntu_medium" android:text="Halaman Barang" android:textColor="#000" android:textSize="18sp" /> </RelativeLayout> </androidx.cardview.widget.CardView> <LinearLayout android:layout_width="match_parent" android:layout_height="600dp" android:layout_below="@id/cardheader" android:orientation="vertical" android:id="@+id/tampil"> <androidx.cardview.widget.CardView android:padding="16dp" android:id="@+id/cardItem" app:cardBackgroundColor="@color/putih" android:layout_width="match_parent" app:cardCornerRadius="10dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginBottom="5dp" android:elevation="4dp" android:layout_marginTop="10dp" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_marginRight="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_height="wrap_content"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/img_item_photo" android:layout_width="55dp" android:layout_height="55dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_gravity="center" android:src="@drawable/makanan" /> <LinearLayout android:id="@+id/edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toEndOf="@id/img_item_photo" android:layout_toRightOf="@id/img_item_photo" android:orientation="vertical"> <TextView android:id="@+id/nama" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16sp" android:fontFamily="@font/ubuntu_medium" android:textStyle="bold" android:text="2 x Nasi Liwet" /> <TextView android:id="@+id/satuan" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16sp" android:layout_marginTop="3dp" android:fontFamily="@font/ubuntu_medium" android:textStyle="bold" android:text="Rp 20.000" /> <TextView android:id="@+id/harga" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" android:fontFamily="@font/ubuntu_medium" android:maxLines="2" android:layout_marginTop="3dp" android:text="Rp 40.000" /> <TextView android:id="@+id/kode" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" android:layout_marginTop="3dp" android:fontFamily="@font/ubuntu_medium" android:text="NL-01" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/btn_delete" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentRight="true" android:src="@drawable/ic_remove"/> </RelativeLayout> </LinearLayout> </androidx.cardview.widget.CardView> <androidx.cardview.widget.CardView android:padding="16dp" android:id="@+id/cardItem1" app:cardBackgroundColor="@color/putih" android:layout_width="match_parent" app:cardCornerRadius="10dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginBottom="5dp" android:elevation="4dp" android:layout_marginTop="10dp" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_marginRight="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_height="wrap_content"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/img_item_photo1" android:layout_width="55dp" android:layout_height="55dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_gravity="center" android:src="@drawable/makanan" /> <LinearLayout android:id="@+id/edit1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toEndOf="@id/img_item_photo" android:layout_toRightOf="@id/img_item_photo" android:orientation="vertical"> <TextView android:id="@+id/nama1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16sp" android:fontFamily="@font/ubuntu_medium" android:textStyle="bold" android:text="1 x Mie Ayam Telur" /> <TextView android:id="@+id/satuan1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16sp" android:layout_marginTop="3dp" android:fontFamily="@font/ubuntu_medium" android:textStyle="bold" android:text="Rp 15.000" /> <TextView android:id="@+id/harga1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" android:fontFamily="@font/ubuntu_medium" android:maxLines="2" android:layout_marginTop="3dp" android:text="Rp 15.000" /> <TextView android:id="@+id/kode1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" android:layout_marginTop="3dp" android:fontFamily="@font/ubuntu_medium" android:text="MA-002" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/btn_delete1" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentRight="true" android:src="@drawable/ic_remove"/> </RelativeLayout> </LinearLayout> </androidx.cardview.widget.CardView> </LinearLayout> <androidx.cardview.widget.CardView android:id="@+id/bottomCardnya" android:layout_below="@+id/tampil" android:layout_alignParentBottom="true" android:layout_width="match_parent" app:cardElevation="6dp" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_gravity="center"> <Button android:id="@+id/btn_tambah" android:layout_width="160dp" android:background="@drawable/tombol" android:layout_height="50dp" android:layout_marginLeft="20dp" android:text="Tambah"/> </LinearLayout> </androidx.cardview.widget.CardView> </RelativeLayout> Copy protected with Online-PDF-No-Copy.com