Anda di halaman 1dari 36

LAPORAN PRAKTIKUM PEMROGRAMAN MOBILE ANDROID JSON-CRUD

NIM : 18650021
NAMA : FATMA INDIKA SARI
KELAS : PRAKTIKUM PEMROGRAMAN MOBILE (G)

1. Pertama buka aplikasi android studio untuk membuat projek.. klik start new project dan beri
nama projek pra_uts_nim_nama_kelas sesuai perintah di modul.
2. Kedua maka akan muncul tampilan seperti pada gambar berikut.. dan langkah selanjutnya
adalah menambah source kode implementation seperti gambar di bawah ini

3. Ketiga kita membuat kelas java pada projek kita dengan nama “Constants” fungsi URL dari kelas
ini untuk mengkoneksikan ke database yang sudah ada
4. Ke empat kita membuat kelas dengan nama “Detail data” .. dalam kelas ini kita menambahkan
source kode untuk : id, nama, phone, dan alamat yang nantinya akan muncul untuk
menambahkan data.

5. Ke lima kita menambahkan kelas java pada projek kita dengan nama “EditActivity” dalam kelas
ini terdapat source kode yang nantinya akan dapat mengedit data yang sudah kita inputkan.
6. Ke enam kita membuat kelas java pada projek kita dengan nama “ListActivity” yang nantinya
data-data yang sudah di masukkan akan muncul di halaman pertama sebelum kita add data dan
setelah add data.

7. Ke tujuh di kelas “MainActivity” kita menambah source kode yang seperti pada perintah modul
8. Ke delapan kita membuat kelas java pada projek dengan nama “Model”

9. Ke sembilan kita membuat kelas java dengan nama “MyAdapter” seperti pada gambar berikut
ini
10. Ke sepuluh ini membuat kelas terakhir java dengan nama “RequestHandler” seeprti pada
gambar berikut ini.

11. Ke sebeleas kita membuat layout dengan nama “activity_detail_data.xml” yang nantinya data-
data secara detail akan muncul.
12. Ke duabelas kita membuat layout dengan nama “Activity_Edit.xml” seperti pada gambar berikut
ini yang nantinya akan menampilkan tampilan sebuah layout untuk mengedit data.

13. Ke tigabelas kita membuat layout dengan nama “Activity_list.xml” yang nantinya pada kelas ini
akan muncul layout dengan tampilan list-list data yang telah di masukkan atau data yang telah
masuk ke database yang sudah terkoneksikan.
14. Ke empatbelas kita membuat layout dengan nama “list_item.xml” seperti pada gambar berikut
ini.

15. Ke limabelas kita menambahkan source kode pada AndroidManifest.xml seperti pada perintah
di modul.
16. Ke enambelas kita menambahkan folder “menu” dan menambahkan layout “add” untuk
tampilan add pada halaman yang akan di tambahkan data.

17. Ke tujuhbelas membuat folder dengan nama “xml” dan menambahkan layout “button” dan
“input” yang nantinya akan memasukkan data ke dalam database dan data tersebut akan ada di
list data .
18. Ke delapan belas disini saya menambahkan gambar icon untuk tampilan “add” .
Hasil :

Pada Saat di run akan muncul gambar seperti di bawah ini, list-list data yang telah masuk akan muncul
pada halaman layout, untuk emnambahkan data klik pojok kanan atas ada icon + untuk menambahkan
data kita.

Tambahkan data ,, contohnya seperti data diri sendiri.


Hasil akhir seperti pada emulator ini, dan data diri saya ada di paling bawah
18650021 Fatma Indika Sari.
---Source Kode Gradle---

apply plugin: 'com.android.application'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.example.pra_uts_18650021_fatmaindikasari_g"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.3'
implementation 'com.android.volley:volley:1.1.1'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:30.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso-
core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
)

}
--- Source Code Class Constants ----

package com.example.pra_uts_18650021_fatmaindikasari_g;

public class Constants {


public static final String URL= "https://lkp2i.co.id/";
public static final String ROOT_URL = URL+"mobileprog/crud_api/";
public static final String URL_ADD = ROOT_URL+"add.php";
public static final String URL_DELETE = ROOT_URL+"delete.php";
public static final String URL_UPDATE = ROOT_URL+"update.php";
public static final String URL_SELECT = ROOT_URL+"select.php";
public static final String URL_SELECT_ID = ROOT_URL+"select_id.php";
}

--- Source Code Class DetailData ----

package com.example.pra_uts_18650021_fatmaindikasari_g;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class DetailData extends AppCompatActivity {


TextView uid, name, address, phone;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_data);
uid = (TextView) findViewById(R.id.uid);
name = (TextView) findViewById(R.id.name);
address = (TextView) findViewById(R.id.address);
phone = (TextView) findViewById(R.id.phone);
uid.setText(getIntent().getStringExtra("uid"));
name.setText(getIntent().getStringExtra("name"));
address.setText(getIntent().getStringExtra("address"));
phone.setText(getIntent().getStringExtra("phone"));
}
}

--- Source Code Class EditActivity ----

import java.util.HashMap;
import java.util.Map;

public class EditActivity extends AppCompatActivity{


EditText uid, name, address, phone;
String Uid, Name, Address, Phone, Id;
Button button;
Boolean valid = true;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);

uid = findViewById(R.id.uid);
name = findViewById(R.id.name);
address = findViewById(R.id.address);
phone = findViewById(R.id.phone);
progressDialog = new ProgressDialog(this);
button = findViewById(R.id.button);

Id = getIntent().getStringExtra("id");
uid.setText(getIntent().getStringExtra("uid"));
name.setText(getIntent().getStringExtra("name"));
address.setText(getIntent().getStringExtra("address"));
phone.setText(getIntent().getStringExtra("phone"));

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uid = uid.getText().toString();
Name = name.getText().toString();
Address = address.getText().toString();
Phone = phone.getText().toString();

if(TextUtils.isEmpty(Uid)){
uid.setError("UID cannot be empty");
valid = false;
}else {
valid = true;

if (TextUtils.isEmpty(Name)){
name.setError("Name cannot be empty");
valid = false;
}else{
valid = true;

if(TextUtils.isEmpty(Address)){
address.setError("Address cannot be empty");
valid = false;
}else{
valid = true;

if(TextUtils.isEmpty(Phone)){
phone.setError("Contact number cannot be empty");
valid = false;
}else{
valid = true;
}
}
}
}
if(valid){
progressDialog.setMessage("Loading");
progressDialog.show();

StringRequest stringRequest = new


StringRequest(Request.Method.POST, Constants.URL_UPDATE, new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try{
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(EditActivity.this,
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
if(jsonObject.getString("message").equals("Edit Data
Successful")){
ListActivity.ma.refresh_list();
finish();
}
}catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.hide();
Toast.makeText(EditActivity.this,
"Failed",Toast.LENGTH_SHORT).show();
}
}){
protected Map<String , String> getParams() throws
AuthFailureError {
Map<String , String> params = new HashMap<>();
params.put("id", Id);
params.put("name", Name);
params.put("uid", Uid);
params.put("phone", Phone);
params.put("address",Address);
return params;
}
};

RequestHandler.getInstance(EditActivity.this).addToRequestQueue(stringRequest);

}
}
});
}
}
--- Source Code Class ListActivity ----

package com.example.pra_uts_18650021_fatmaindikasari_g;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ListActivity extends AppCompatActivity{
public static ListActivity ma;
protected Cursor cursor;
ArrayList<Model> thelist;
ListView listview;
List<Model> listItems;
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
getSupportActionBar().setTitle("Data");
recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager( ListActivity.this));
progressDialog = new ProgressDialog( this);
listItems = new ArrayList<>();
ma = this;
refresh_list();
}

public boolean onCreateOptionsMenu(Menu menu) {


getMenuInflater().inflate(R.menu.add, menu);
return true;
}

public boolean onOptionsItemSelected(MenuItem item) {


int id = item.getItemId();
if (id == R.id.add) {
Intent tes = new Intent(ListActivity.this, MainActivity.class);
startActivity(tes);
}
return super.onOptionsItemSelected(item);
}

public void refresh_list(){


listItems.clear();
adapter = new MyAdapter(listItems,getApplicationContext());
recyclerView.setAdapter(adapter);

recyclerView.setItemAnimator(new DefaultItemAnimator());
progressDialog.setMessage("Loading");
progressDialog.show();

StringRequest stringRequest = new StringRequest(Request.Method.POST,


Constants.URL_SELECT, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {

progressDialog.hide();
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("data");

Toast.makeText(ListActivity.this,
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject o = jsonArray.getJSONObject(i);
Model item = new Model(
o.getString("id"),
o.getString("uid"),
o.getString("name"),
o.getString("phone"),
o.getString("address")
);
listItems.add(item);
adapter = new MyAdapter(listItems, getApplicationContext());
recyclerView.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.hide();
Toast.makeText(ListActivity.this, "Failed",
Toast.LENGTH_SHORT).show();
}
}) {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("name", "kl");
return params;
}
};

RequestHandler.getInstance(ListActivity.this).addToRequestQueue(stringRequest);
}
}

--- Source Code Class MainActivity ----

package com.example.pra_uts_18650021_fatmaindikasari_g;

import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

EditText uid, name, address, phone;


String Uid, Name, Address, Phone;
Button button;
Boolean valid = true;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

uid = (EditText) findViewById(R.id.uid);


name = (EditText) findViewById(R.id.name);
address = (EditText) findViewById(R.id.address);
phone = (EditText) findViewById(R.id.phone);
progressDialog = new ProgressDialog(this);
button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uid = uid.getText().toString();
Name = name.getText().toString();
Address = address.getText().toString();
Phone = phone.getText().toString();

if(TextUtils.isEmpty(Uid)){
uid.setError("UID Cannot be Empty");
valid = false;
}else {
valid = true;

if(TextUtils.isEmpty(Name)){
name.setError("Name Cannot be Empty");
valid = false;
}else {
valid = true;

if(TextUtils.isEmpty(Address)){
address.setError("Address Cannot be Empty");
valid = false;
}else {
valid = true;

if(TextUtils.isEmpty(Phone)){
phone.setError("Contact Number Cannot be Empty");
valid = false;
}else {
valid = true;
}
}

}
}

if(valid){
progressDialog.setMessage("Loading");
progressDialog.show();

StringRequest stringRequest = new


StringRequest(Request.Method.POST, Constants.URL_ADD, new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try{
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(MainActivity.this,
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
if(jsonObject.getString("message").equals("Data Added
Successfully")){
ListActivity.ma.refresh_list();
finish();
}
}catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.hide();
Toast.makeText(MainActivity.this, "Failed to
Data",Toast.LENGTH_SHORT).show();
}
}){
protected Map<String , String> getParams() throws
AuthFailureError {
Map<String , String> params = new HashMap<>();
params.put("name", Name);
params.put("uid", Uid);
params.put("phone", Phone);
params.put("address",Address);
return params;
}
};

RequestHandler.getInstance(MainActivity.this).addToRequestQueue(stringRequest);

}
}
});

}
--- Source Code Class Model ----

package com.example.pra_uts_18650021_fatmaindikasari_g;

public class Model {


String id, uid, name, phone, address;

public Model(String id, String uid, String name, String phone, String address){
this.id=id;
this.uid=uid;
this.name=name;
this.phone=phone;
this.address=address;
}
public String getId(){
return id;
}
public String getUid(){
return uid;
}
public String getName(){
return name;
}
public String getPhone(){
return phone;
}
public String getAddress(){
return address;
}
}

--- Source Code Class MyAdapter ----

package com.example.pra_uts_18650021_fatmaindikasari_g;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
private List<Model> listItems;
private Context context;
private ProgressDialog dialog;

public MyAdapter(List<Model> listItems, Context context) {


this.listItems = listItems;
this.context = context;
}

public class ViewHolder extends RecyclerView.ViewHolder {

public TextView id;


public TextView uid;
public TextView name;
public TextView address;
public TextView phone;
public CardView card_view;
public ViewHolder(View itemView ) {
super(itemView);
id = (TextView) itemView.findViewById(R.id.id);
uid = (TextView) itemView.findViewById(R.id.uid);
name = (TextView) itemView.findViewById(R.id.name);
address = (TextView) itemView.findViewById(R.id.address);
phone = (TextView) itemView.findViewById(R.id.phone);
card_view = (CardView) itemView.findViewById(R.id.card_view);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,
parent, false);
return new ViewHolder(v);
}

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
final Model listItem = listItems.get(position);
holder.id.setText(listItem.getId());
holder.uid.setText(listItem.getUid());
holder.name.setText(listItem.getName());
holder.address.setText(listItem.getAddress());
holder.phone.setText(listItem.getPhone());

holder.card_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
Intent intent;
AlertDialog.Builder builder = new
AlertDialog.Builder(view.getContext());
final ProgressDialog dialog = new ProgressDialog(view.getContext());
dialog.setMessage("Loading Delete Data");
final CharSequence[] dialogitem = {"View Data","Edit Data","Delete
Data"};
builder.setTitle(listItem.getName());
builder.setItems(dialogitem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch (i){
case 0 :
Intent intent = new Intent(view.getContext(),
DetailData.class);
intent.putExtra("id", listItem.getId());
intent.putExtra("uid",listItem.getUid());
intent.putExtra("name",listItem.getName());
intent.putExtra("address",listItem.getAddress());
intent.putExtra("phone", listItem.getPhone());
view.getContext().startActivity(intent);
break;
case 1 :

Intent intent2 = new Intent(view.getContext(),


EditActivity.class);
intent2.putExtra("id", listItem.getId());
intent2.putExtra("uid",listItem.getUid());
intent2.putExtra("name",listItem.getName());
intent2.putExtra("address",listItem.getAddress());
intent2.putExtra("phone", listItem.getPhone());
view.getContext().startActivity(intent2);
break;
case 2 :

AlertDialog.Builder builderDel = new


AlertDialog.Builder(view.getContext());
builderDel.setTitle(listItem.getName());
builderDel.setMessage("Are You Sure, You Want to
Delete Data?");
builderDel.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface
dialogInterface, int i) {
dialog.show();

StringRequest stringRequest = new


StringRequest(Request.Method.POST, Constants.URL_DELETE, new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
dialog.hide();
dialog.dismiss();

Toast.makeText(view.getContext(),"Successfully Deleted Data "+


listItem.getName(),Toast.LENGTH_LONG).show();
ListActivity.ma.refresh_list();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError
error) {
dialog.hide();
dialog.dismiss();
}
}){
protected HashMap<String, String>
getParams() throws AuthFailureError {
Map<String, String> params= new
HashMap<>();
params.put("id",listItem.getId());
return (HashMap<String, String>)
params;

}
};

RequestHandler.getInstance(view.getContext()).addToRequestQueue(stringRequest);
dialogInterface.dismiss();
}
});

builderDel.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
@Override

public void onClick(DialogInterface


dialogInterface, int i) {
dialogInterface.dismiss();
}
});

builderDel.create().show();
break;
}
}
});

builder.create().show();
}
});
}

@Override
public int getItemCount() {
return listItems.size();
}
}

--- Source Code Class RequestHandler ----

package com.example.pra_uts_18650021_fatmaindikasari_g;
import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
public class RequestHandler {
private static RequestHandler mInstance;
private RequestQueue mRequestQueue;
private static Context mCtx;

private RequestHandler(Context context) {


mCtx = context;
mRequestQueue = getRequestQueue();
}

public static synchronized RequestHandler getInstance(Context context) {


if (mInstance == null) {
mInstance = new RequestHandler(context);
}
return mInstance;
}

public RequestQueue getRequestQueue() {


if (mRequestQueue == null) {

mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
}
return mRequestQueue;
}

public <T> void addToRequestQueue(Request<T> req) {


getRequestQueue().add(req);
}
}

--- Source Code Layout Activity_Detail_Data ----


<?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=".DetailData">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="14dp"
android:orientation="vertical"
android:padding="20dp">

<TextView
android:id="@+id/textView12"
android:textSize="22sp"
android:layout_marginBottom="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Data"
android:textColor="#546e7a"/>

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UID"
android:textColor="#222"
android:textStyle="bold"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uid"
android:textSize="19sp"
android:layout_marginBottom="20dp"/>

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#222"
android:textStyle="bold"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"
android:textSize="19sp"
android:layout_marginBottom="20dp"/>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Number"
android:textColor="#222"
android:textStyle="bold"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone"
android:textSize="19sp"
android:layout_marginBottom="20dp"/>

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#222"
android:textStyle="bold"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/address"
android:textSize="19sp"
android:layout_marginBottom="20dp"/>

</LinearLayout>

</ScrollView>
</RelativeLayout>

--- Source Code Layout Activity_Edit ----

<?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=".EditActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="14dp"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/textView12"
android:textSize="22sp"
android:layout_marginBottom="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Edit Data"
android:textColor="#546e7a"/>

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UID"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="number"/>

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="text"/>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Number"
android:textColor="#546e7a"/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="phone"/>

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="text"/>

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update Data"
android:background="@xml/button"
android:textColor="#fff"/>

</LinearLayout>

</ScrollView>
</RelativeLayout>

--- Source Code Layout Activity_List ----

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
android:orientation="vertical"
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="com.example.pra_uts_18650021_fatmaindikasari_g.ListActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

--- Source Code Layout Activity_Main ----

<?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">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="14dp"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/textView12"
android:textSize="22sp"
android:layout_marginBottom="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Data"
android:textColor="#546e7a"/>

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UID"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="number"/>

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="text"/>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Number"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"
android:background="@xml/input"
android:layout_marginBottom="10dp"
android:inputType="phone"/>

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#546e7a"/>

<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="10dp"

android:layout_marginBottom="10dp"
android:inputType="text"/>

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Data"
android:background="@xml/button"
android:textColor="#fff"/>

</LinearLayout>

</ScrollView>

</RelativeLayout>

--- Source Code Layout list_item ----

<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="3dp"
android:paddingBottom="3dp">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:elevation="14dp"
android:id="@+id/card_view"
android:layout_marginBottom="2dp">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">

<TextView
android:id="@+id/uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_marginBottom="3dp"
android:textSize="16dp"
android:textColor="#2196f3"/>

<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:textSize="12dp"
android:textColor="#878586"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#2196f3"
android:visibility="invisible"/>

<TextView
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:textSize="10dp" android:textColor="#aeaeae"/>

<TextView
android:visibility="invisible"
android:layout_alignParentRight="true"
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:textSize="10dp"
android:textColor="#aeaeae"/>

</RelativeLayout>

</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

--- Source Code AndroidManifest ----

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pra_uts_18650021_fatmaindikasari_g">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity

android:name="com.example.pra_uts_18650021_fatmaindikasari_g.MainActivity"

android:parentActivityName="com.example.pra_uts_18650021_fatmaindikasari_g.ListActivi
ty" />
<activity
android:name="com.example.pra_uts_18650021_fatmaindikasari_g.ListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.pra_uts_18650021_fatmaindikasari_g.DetailData"

android:parentActivityName="com.example.pra_uts_18650021_fatmaindikasari_g.ListActivi
ty" />
<activity
android:name="com.example.pra_uts_18650021_fatmaindikasari_g.EditActivity"

android:parentActivityName="com.example.pra_uts_18650021_fatmaindikasari_g.ListActivi
ty"
></activity>
</application>

</manifest>

--- Source Code Menu Add ----

<?xml version="1.0" encoding="utf-8"?>


<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Add Data"
android:id="@+id/add"
android:orderInCategory="100"
android:icon="@drawable/add"
app:showAsAction="always" />
</menu>

--- Source Code Xml Button ----

<?xml version="1.0" encoding="utf-8"?>


<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle" android:background="#1976d2">

<solid android:color="#1976d2" />


<corners android:radius="5dp" />
<stroke
android:width="0.5dp"
android:color="#1976d2"
/>
</shape>
</item>
</selector>

--- Source Code Xml Input ----

<?xml version="1.0" encoding="utf-8"?>


<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle" android:background="#fafafa">

<solid android:color="#fafafa" />


<corners android:radius="5dp" />
<stroke
android:width="0.5dp"
android:color="#dddddd"
/>
</shape>
</item>
</selector>

Anda mungkin juga menyukai