Anda di halaman 1dari 33

LABORATORIUM PEMBELAJARAN ILMU KOMPUTER

FAKULTAS ILMU KOMPUTER


UNIVERSITAS BRAWIJAYA
BAB : UI WIDGET
NAMA : ALFEN HASIHOLAN
NIM : 185150207111021
TANGGAL : 02/11/2020
ASISTEN : - LABIB ALFARUQI IBRAHIM
- NUR FAJRI HAYYUNI MAULIDYA

TUGAS 1
A. Soal
Buatlah aplikasi Android yang dapat menampilkan setiap aktivitas siklus hidup
Android yang menerapkan onCreate, onStart, onRestart, onResume, onPause,
onStop, dan onDestroy.

B. Source Code
Activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayout
3 xmlns:android="http://schemas.android.com/apk/res/
4 android"
5
6 xmlns:app="http://schemas.android.com/apk/res-
7 auto"
8 xmlns:tools="http://schemas.android.com/tools"
9 android:layout_width="match_parent"
10 android:layout_height="match_parent"
11 tools:context=".MainActivity">
12
13 <TextView
14
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content"
17 android:text="Hello World!"
18 app:layout_constraintBottom_toBottomOf="pare
19 nt"
20 app:layout_constraintLeft_toLeftOf="parent"
21 app:layout_constraintRight_toRightOf="parent
22 " app:layout_constraintTop_toTopOf="parent"
23 />
24 </androidx.constraintlayout.widget.Constrain
25 tLayout>
26

MainActivity.kt
1 package com.example.activity
2
3 import androidx.appcompat.app.AppCompatActivity
4 import android.os.Bundle
5 import android.util.Log
6
7 class MainActivity : AppCompatActivity() {
8 override fun onCreate(savedInstanceState:
9 Bundle?) {
10 super.onCreate(savedInstanceState)
11 Log.i("callback", "OnCreate")
12 setContentView(R.layout.activity_main)
13 }
14
15 override fun onStart(){
16 Log.i("callback","onStart")
17 super.onStart()
18 }
19
20 override fun onResume(){
21 Log.i("callback","onResume")
22 super.onResume()
23 }
24
25 override fun onPause(){
26 Log.i("callback","onPause")
27 super.onPause()
28 }
29
30 override fun onStop(){
31 Log.i("callback","onStop")
32 super.onStop()
33 }
34
35 override fun onRestart(){
36 Log.i("callback","onRestart")
37 super.onRestart()
38 }
39
40 override fun onDestroy(){
41 Log.i("callback","onDestroy")
42 super.onDestroy()
43 }
44 }

C. Screenshot
1. Pertama kali aplikasi dijalankan
2. Saat menekan tombol home di Android

3. Saat membuka kembali aplikasi dari task manager android.


4. Terkakhir kita akan menutup aplikasi dengan tombol back pada android
dan ke home screen.

D. Penjelasan
Jadi pada percobaan kali ini, kita akan mencoba menampilkan setiap
activity yang kita lakukan terhadap aplikasi ini sesuai dengan android lifecycle.
Untuk itu, seperti yang bisa dilihat pada class MainActivity.kt, pertama kita
akan membuat function onCreate, onStart, , onResume, onPause, onStop,
onRestart dan onDestroy sebagai activity yang akan dilakukan pada aplikasi.
Kemudian di setiap function ada syntax Log.i(). Syntax Log.i() ini berguna
untuk menampilkan atau ibaratnya seperti merekam setiap activity yang akan
dilakukan dan activity-nya akan muncul pada bagian bawah project Android
Studio, yakni di console seperti yang ada pada gambar screenshot di atas.

Syntax Log.i() ini sendiri terdiri dari 2 parameter yakni tag dan message.
Untuk tag diberi nama callback dan message diberi nama sesuai dengan
callback yang sedang dipanggil atau sesuai nama fungsinya. Hal itu bisa dilihat
pada MainActivity.kt. Jadi untuk proses percobaanya seperti ini. Pertama kita
jalankan program dengan emulator yang ada( disini saya menggunakaan
device Android asli). Kita akan langsung masuk ke aplikasi “Hello World”.
Pada proses ini, callback akan menjalankan fungsi onCreate, onStart dan
onResume seperti di gambar 1. Setelah itu, kita akan menekan tombol home di
android sehingga kita masuk ke home screen. Di sini, proses yang akan
dijalankan adalah fungsi onPause dan onStop seperti pada gambar 2.
Kemudian kita akan masuk kembali ke dalam aplikasinya lewat task manager
dengan klik kiri pada android dan kita masuk kembali ke aplikasinya. Disini,
callback akan menjalankan fungsi onRestart, onStart dan onResume seperti
pada gambar 3. Terakhir kita akan menutup aplikasi dengan menekan tombol
back. Disini, callback akhirnya akan menjalankan fungsi onPause, onStop dan
onDestroy.
TUGAS 2
A. Soal
Buatlah sebuah UI bertemakan biodata yang memuat minimal 1 layout, 2 tipe
text, dan 3 button.

B. Source Code
layout_biodata.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <ScrollView
3 xmlns:android="http://schemas.android.com/apk/res
4 /android"
5 xmlns:app="http://schemas.android.com/apk/res
6 -auto"
7 android:layout_height="match_parent"
8 android:layout_width="match_parent"
9 android:orientation="vertical">
10
11 <LinearLayout
12 android:layout_width="match_parent"
13 android:layout_height="match_parent"
14 android:orientation="vertical">
15
16 <LinearLayout
17 android:layout_width="match_parent"
18 android:layout_height="183dp"
19 android:background="@color/colorPrimary
20 "
21 android:gravity="center"
22 android:orientation="vertical">
23
24 <ImageView
25 android:layout_width="100dp"
26 android:layout_height="100dp"
27 android:src="@drawable/ic_mainland" />
28
29 <TextView
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:layout_marginTop="10dp"
33 android:text="Form Biodata"
34 android:textColor="@color/warnalain"
35 android:textSize="25dp" />
36 </LinearLayout>
37
38 <LinearLayout
39 android:layout_width="match_parent"
40 android:layout_height="607dp"
41 android:orientation="vertical"
42 android:padding="50dp">
43
44 <EditText android:id="@+id/nama"
45 android:layout_width="match_parent"
46 android:layout_height="wrap_content"
47 android:hint="Masukkan nama lengkap"
48 android:inputType="text" />
49
50 <EditText android:id="@+id/email"
51 android:layout_width="match_parent"
52 android:layout_height="wrap_content"
53 android:hint="Masukkan alamat email"
54 android:inputType="textEmailAddress" />
55
56 <EditText android:id="@+id/inputPassword"
57 android:layout_width="match_parent"
58 android:layout_height="wrap_content"
59 android:hint="Masukkan password"
60 android:inputType="textPassword" />
61
62 <EditText android:id="@+id/noTelp"
63 android:layout_width="323dp"
64 android:layout_height="wrap_content"
65 android:hint="Masukkan nomor telepon"
66 android:inputType="number" />
67
68 <LinearLayout
69 android:layout_width="match_parent"
70 android:layout_height="wrap_content"
71 android:orientation="horizontal">
72
73 <RadioButton
74 android:layout_width="156dp"
75 android:layout_height="wrap_content"
76 android:text="Pria" />
77
78 <RadioButton
79 android:layout_width="167dp"
80 android:layout_height="wrap_content"
81 android:text="Wanita" />
82
83 </LinearLayout>
84
85 <LinearLayout
86 android:layout_width="match_parent"
87 android:layout_height="wrap_content"
88 android:orientation="horizontal">
89
90 <RadioButton
100 android:layout_width="156dp"
101 android:layout_height="wrap_content"
102 android:text="WNI" />
103
104 <RadioButton
105 android:layout_width="167dp"
106 android:layout_height="wrap_content"
107 android:text="WNA" />
108
109 </LinearLayout>
110
111 <CheckBox
112 android:id="@+id/checkBox1"
113 android:layout_width="match_parent"
114 android:layout_height="wrap_content"
115 android:text="Dengan ini, anda sudah
116 setuju dengan semua syarat dan
117 ketentuan dari perusahaan kami." />
118 <CheckBox
119 android:id="@+id/checkBox2"
120 android:layout_width="match_parent"
121 android:layout_height="wrap_content"
122 android:text="Anda setuju untuk
123 mendapatkan informasi terbaru seputar
124 produk kami." />
125
126 <Button android:id="@+id/button3"
127 android:layout_width="match_parent"
128 android:layout_height="wrap_content"
129 android:text="Lanjut" />
130
131 android:layout_width="match_parent"
132 android:layout_height="match_parent">
133
134 <LinearLayout
135 android:layout_width="match_parent"
136 android:layout_height="wrap_content"
137 android:orientation="vertical" />
138 </LinearLayout>
139 </LinearLayout>
140 </ScrollView>
141

MainActivity.kt
1 package com.example.activity
2
3 import androidx.appcompat.app.AppCompatActivity
4 import android.os.Bundle
5 import android.util.Log
6
7 class MainActivity : AppCompatActivity() {
8 override fun onCreate(savedInstanceState:
9 Bundle?) {
10 super.onCreate(savedInstanceState)
11 setContentView(R.layout.layout_biodata)
12 }
C. Screenshot
D. Penjelasan
Pada percobaan ini, kita akan membuat suatu layout form biodata yang
dimana kita menggunakan LinearLayout sebagai root dari semua widget dan
ViewGroup. Di sini saya menggunakan ScrollView sehingga layer/ layout
nanti bisa di-scroll(di gerakkan) ke atas-bawah. Kita bisa melihat
LinearLayout pertama(linear1) pada baris ke-11 yang akan berfungsi untuk
membungkus keseluruhan view dan ViewGroup dan ukuran panjang & lebar
layout akan mengikuti ukuran layar Android. Di dalam LinearLayout ini,
terdapat LinearLayout yang kedua(linear2) lagi dari baris 16-36 yang
berisikan ImageView yakni untuk menampilkan logo dan TextView untuk
menampilkan tulisan “Form Biodata”. Untuk TextView sendiri ukurannya
menyesuaikan dengan panjang text yang dibuat (wrap_content).

Kemudian kita masuk ke LinearLayout ketiga(linear3). Di dalam layout


ini terdapat 4 widget EditText. EditText pertama sebagai kolom untuk
memasukkan nama lengkap, EditText kedua untuk memasukkan alamt email,
EditText ketiga untuk memasukkan password dan EditText keempat untuk
memasukkan nomor telepon. Setelah itu kita masuk ke LinearLayout
keempat(linear4) yang di dalam ini terdapat 2 widget RadioButton dengan
orientation horizontal untuk memilih jenis kelamin yakni Pria atau Wanita.
Kemudian masuk ke Linear yang kelima (linear5) yang fungsi dan elemen-
nya sama persis dengan linear4 yakni memiliki 2 widget RadioButton untuk
memilih kewarganegaraan yakni WNI atau WNA. Setelah itu, kita akan
menggunakan 2 widget checkbox sebagai tanda persetujuan dengan syarat dan
tawaran dari perusahaan. Kemudian saya menggunakan widget Button sebagai
tombol submit form.

TUGAS 3
A. Soal
Buatlah implementasi 2 fragment. Fragment pertama mengimplementasikan
imageview. Fragment kedua dapat berisi apapun sesuai kreativitas Anda
(sebagai contoh : form).

B. Source Code
a. Fragment Imageview

ChatFragment.java
1 package com.example.belajarfragment;
2
3 import android.os.Bundle;
4
5 import androidx.fragment.app.Fragment;
6
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 import android.widget.ImageView;
11
12 public class ChatFragment extends Fragment {
13 private ImageView imageView321;
14
15 // the fragment initialization parameters,
16 e.g. ARG_ITEM_NUMBER
17 private static final String ARG_PARAM1 =
18 "param1";
19 private static final String ARG_PARAM2 =
20 "param2";
21
22 // TODO: Rename and change types of
23 parameters
24 private String mParam1;
25 private String mParam2;
26
27 public ChatFragment() {
28
29 // Required empty public constructor
30 }
31
32 // TODO: Rename and change types and number
33 of parameters
34 public static ChatFragment newInstance(String
35 param1, String param2) {
36 ChatFragment fragment = new ChatFragment();
37 Bundle args = new Bundle();
38 args.putString(ARG_PARAM1, param1);
39 args.putString(ARG_PARAM2, param2);
40 fragment.setArguments(args);
41 return fragment;
42
43 }
44
45 @Override
46
47 public void onCreate(Bundle
48 savedInstanceState) {
49 super.onCreate(savedInstanceState);
50 if (getArguments() != null) {
51 mParam1 =
52 getArguments().getString(ARG_PARAM1);
53 mParam2 =
54 getArguments().getString(ARG_PARAM2);
55 }
56
57 }
58
59 @Override
60 public View onCreateView(LayoutInflater
61 inflater, ViewGroup container, Bundle
62 savedInstanceState) {
63
64 // Inflate the layout for this fragment
65 View view =
66 inflater.inflate(R.layout.fragment_chat,
67 container, false);
68
69 imageView321 =
70 view.findViewById(R.id.pulisic);
71 return view;
72 }
73 }
74

HomeFragment.java
1 package com.example.belajarfragment;
2
3 import android.os.Bundle;
4
5 import androidx.fragment.app.Fragment;
6
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 import android.widget.ImageView;
11
12 public class HomeFragment extends Fragment {
13 private ImageView imageview123;
14
15 // TODO: Rename parameter arguments, choose
16 names that match
17 // the fragment initialization parameters,
18 e.g. ARG_ITEM_NUMBER
19 private static final String ARG_PARAM1 =
20 "param1";
21 private static final String ARG_PARAM2 =
22 "param2";
23
24 // TODO: Rename and change types of
25 parameters
26 private String mParam1;
27 private String mParam2;
28
29 public HomeFragment() {
30 // Required empty public constructor
31 }
32
33 // TODO: Rename and change types and number
34 of parameters
35 public static HomeFragment newInstance(String
36 param1, String param2) {
37 HomeFragment fragment = new
38 HomeFragment();
39 Bundle args = new Bundle();
40 args.putString(ARG_PARAM1, param1);
41 args.putString(ARG_PARAM2, param2);
42 fragment.setArguments(args);
43 return fragment;
44 }
45
46 @Override
47 public void onCreate(Bundle
48 savedInstanceState) {
49 super.onCreate(savedInstanceState);
50 if (getArguments() != null) {
51 mParam1 =
52 getArguments().getString(ARG_PARAM1);
53 mParam2 =
54 getArguments().getString(ARG_PARAM2);
55 }
56 }
57
58 @Override
59 public View onCreateView(LayoutInflater
60 inflater, ViewGroup container, Bundle
61 savedInstanceState) {
62 // Inflate the layout for this fragment
63 View view =
64 inflater.inflate(R.layout.fragment_home,
65 container, false);
66 imageview123 =
67 view.findViewById(R.id.havertz);
68 return view;
69 }
70 }

MainActivity.java
1 package com.example.belajarfragment;
2
3 import android.os.Bundle;
4 import android.view.View;
5 import android.widget.Button;
6
7 import androidx.appcompat.app.AppCompatActivity;
8 import androidx.fragment.app.FragmentManager;
9 import androidx.fragment.app.FragmentTransaction;
10
11 public class MainActivity extends
12 AppCompatActivity {
13
14 Button button1, button2;
15 @Override
16 protected void onCreate(Bundle
17 savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.activity_main);
20
21 button1 =
22 findViewById(R.id.button_fragment1);
23 button2 =
24 findViewById(R.id.button_fragment2);
25
26 button1.setOnClickListener(new
27 View.OnClickListener() {
28 @Override
29 public void onClick(View v) {
30 FragmentManager fm =
31 getSupportFragmentManager();
32 //fm.beginTransaction().add(R.id.con
33 tainer,new HomeFragment()).commit();
34 FragmentTransaction ft =
35 fm.beginTransaction();
36 ft.replace(R.id.container, new
37 HomeFragment());
38 ft.commit();
39 }
40 });
41 button2.setOnClickListener(new
42 View.OnClickListener() {
43 @Override
44 public void onClick(View v) {
45 FragmentManager fm =
46 getSupportFragmentManager();
47 //fm.beginTransaction().add(R.id.con
48 tainer,new ChatFragment()).commit();
49 FragmentTransaction ft =
50 fm.beginTransaction();
51 ft.replace(R.id.container, new
52 ChatFragment());
53 ft.commit();
54 }
55 });
56
57 }
58 }

activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/
4 android"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:layout_width="match_parent"
7 android:layout_height="match_parent"
8 android:orientation="vertical"
9 tools:context=".MainActivity"
10 android:background="@drawable/background_gradie
11 nt">
12
13 <LinearLayout
14 android:layout_width="match_parent"
15 android:layout_height="wrap_content"
16 android:orientation="horizontal"
17 android:layout_margin="15dp"
18 android:layout_marginStart="10dp"
19 android:layout_marginEnd="10dp">
20
21 <Button
22 android:id="@+id/button_fragment1"
23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:layout_weight="1"
26 android:background="@drawable/gradient"
27 android:text="Fragment #1 " />
28
29 <Button
30 android:id="@+id/button_fragment2"
31 android:layout_width="wrap_content"
32 android:layout_height="wrap_content"
33 android:layout_marginLeft="10dp"
34 android:layout_weight="1"
35 android:background="@drawable/gradient"
36 android:text="Fragment #2" />
37 </LinearLayout>
38
39 <FrameLayout android:id="@+id/container"
40 android:layout_width="match_parent"
41 android:layout_height="match_parent">
42 </FrameLayout>
43
44 </LinearLayout>

fragment_home.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/
4 android"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:layout_width="match_parent"
7 android:layout_height="match_parent"
8 android:orientation="horizontal"
9 tools:context=".HomeFragment">
10
11 <!-- TODO: Update blank fragment layout -->
12 <ImageView
13 android:id="@+id/havertz"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:src="@drawable/havertz29"/>
17 </LinearLayout>

fragment_chat.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <RelativeLayout
3 xmlns:android="http://schemas.android.com/apk/res/
4 android"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:layout_width="match_parent"
7 android:layout_height="match_parent"
8 tools:context=".ChatFragment">
9
10 <!-- TODO: Update blank fragment layout -->
11 <ImageView
12 android:id="@+id/pulisic"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:src="@drawable/pulisic10"/>
16 </RelativeLayout>
b. Fragment Form

MainActivity.java
1 package com.example.myfragment;
2
3 import android.os.Bundle;
4
5 import androidx.appcompat.app.AppCompatActivity;
6 import androidx.fragment.app.Fragment;
7 import androidx.fragment.app.FragmentManager;
8 import androidx.fragment.app.FragmentTransaction;
9
10 public class MainActivity extends
11 AppCompatActivity implements CallbackFragment {
12 Fragment fragment;
13 FragmentManager fragmentManager;
14 FragmentTransaction fragmentTransaction;
15
16 @Override
17 protected void onCreate(Bundle
18 savedinstanceState) {
19 super.onCreate(savedinstanceState);
20 setContentView(R.layout.activity_main);
21 addFragment();
22 }
23
24 public void addFragment() {
25 FragmentLogin fragment = new
26 FragmentLogin();
27 fragment.setCallbackFragment(this);
28 fragmentManager =
29 getSupportFragmentManager();
30 fragmentTransaction =
31 fragmentManager.beginTransaction();
32 fragmentTransaction.add(R.id.fragmentConta
33 iner, fragment);
34 fragmentTransaction.commit();
35 }
36
37 public void replaceFragment() {
38 fragment = new FragmentRegister();
39 fragmentManager =
40 getSupportFragmentManager();
41 fragmentTransaction =
42 fragmentManager.beginTransaction();
43 fragmentTransaction.addToBackStack(null);
44 fragmentTransaction.replace(R.id.fragmentC
45 ontainer, fragment);
46 fragmentTransaction.commit();
47 }
48
49 @Override
50 public void changeFragment() {
51 replaceFragment(); }
52 }
FragmentRegister.java
1 package com.example.myfragment;
2
3 import android.content.Context;
4 import android.content.SharedPreferences;
5 import android.os.Bundle;
6 import android.view.LayoutInflater;
7 import android.view.View;
8 import android.view.ViewGroup;
9 import android.widget.Button;
10 import android.widget.EditText;
11 import android.widget.RadioGroup;
12 import android.widget.Toast;
13
14 import androidx.annotation.NonNull;
15 import androidx.annotation.Nullable;
16 import androidx.fragment.app.Fragment;
17
18 public class FragmentRegister extends Fragment {
19
20 Button btnRegister;
21 EditText etUserName, etPassword, etEmail;
22 String userName, pass, email;
23 SharedPreferences sharedPreferences;
24 SharedPreferences.Editor editor;
25 RadioGroup radioGroup;
26
27 @Override
28 public void onAttach(Context context) {
29 sharedPreferences =
30 context.getSharedPreferences("usersFile",
31 Context.MODE_PRIVATE);
32 editor = sharedPreferences.edit();
33 super.onAttach(context);
34 }
35
36 @Nullable
37 @Override
38 public View onCreateView(@NonNull
39 LayoutInflater inflater, @Nullable ViewGroup
40 container, @Nullable Bundle savedInstanceState)
41 {
42 View view =
43 inflater.inflate(R.layout.registered_fragmen
44 t, container, false);
45 etUserName =
46 view.findViewById(R.id.etUserName);
47 etPassword =
48 view.findViewById(R.id.etPassword);
49 etEmail = view.findViewById(R.id.etEmail);
50 btnRegister =
51 view.findViewById(R.id.btnRegistered);
52 radioGroup =
53 view.findViewById(R.id.radiogroup);
54
55 radioGroup.setOnCheckedChangeListener(new
56 RadioGroup.OnCheckedChangeListener() {
57 @Override
58 public void onCheckedChanged(RadioGroup
59 group, int checkedId) {
60 switch(checkedId){
61 case R.id.Pria:
62 Toast.makeText(getContext(),"",T
63 oast.LENGTH_SHORT).show();
64 break;
65 case R.id.Wanita:
66 Toast.makeText(getContext(),"",T
67 oast.LENGTH_SHORT).show();
68 break;
69 }
70 }
71 });
72
73 btnRegister.setOnClickListener(new
74 View.OnClickListener() {
75 @Override
76 public void onClick(View v) {
77 userName =
78 etUserName.getText().toString();
79 email = etEmail.getText().toString();
80 pass =
81 etPassword.getText().toString();
82 editor.putString("userName",
83 userName);
84 editor.putString("pass", pass);
85 editor.putString("email", email);
86 editor.apply();
87 Toast.makeText(getContext(),
88 "Registered",
89 Toast.LENGTH_SHORT).show();
90 }
91 });
92 return view;
93 }
94 }
95

FragmentLogin.java
1 package com.example.myfragment;
2
3 import android.content.Context;
4 import android.content.SharedPreferences;
5 import android.os.Bundle;
6 import android.view.LayoutInflater;
7 import android.view.View;
8 import android.view.ViewGroup;
9 import android.widget.Button;
10 import android.widget.EditText;
11 import android.widget.TextView;
12 import android.widget.Toast;
13
14 import androidx.annotation.NonNull;
15 import androidx.annotation.Nullable;
16 import androidx.fragment.app.Fragment;
17
18 public class FragmentLogin extends Fragment {
19
20 Button btnLogin;
21 TextView daftar;
22 EditText etUserName, etPassword;
23 CallbackFragment callbackFragment;
24 String userName, pass;
25 SharedPreferences sharedPreferences;
26 SharedPreferences.Editor editor;
27
28 @Override
29 public void onAttach(Context context) {
30 sharedPreferences =
31 context.getSharedPreferences("usersFile",
32 Context.MODE_PRIVATE);
33 editor = sharedPreferences.edit();
34 super.onAttach(context);
35 }
36
37 @Nullable
38 @Override
39 public View onCreateView(@NonNull
40 LayoutInflater inflater, @Nullable ViewGroup
41 container, @Nullable Bundle savedInstanceState)
42 {
43 View view =
44 inflater.inflate(R.layout.login_fragment,
45 container, false);
46 etUserName =
47 view.findViewById(R.id.etUserName);
48 etPassword =
49 view.findViewById(R.id.etPassword);
50 btnLogin = view.findViewById(R.id.btnLogin);
51 daftar = view.findViewById(R.id.daftar);
52
53 btnLogin.setOnClickListener(new
54 View.OnClickListener() {
55 @Override
56 public void onClick(View v) {
57 userName =
58 etUserName.getText().toString();
59 pass =
60 etPassword.getText().toString();
61 String uName, uPass;
62 uName =
63 sharedPreferences.getString("userName"
64 , "null");
65 uPass =
66 sharedPreferences.getString("pass",
67 "null");
68
69 if (userName.equals(uName) &&
70 pass.equals(uPass)) {
71 Toast.makeText(getContext(),
72 "Login",
73 Toast.LENGTH_SHORT).show();
74 } else {
75 Toast.makeText(getContext(),
76 "Error",
77 Toast.LENGTH_SHORT).show();
78 }
79 }
80 });
81
82 daftar.setOnClickListener(new
83 View.OnClickListener() {
84 @Override
85 public void onClick(View v) {
86 if (callbackFragment != null) {
87 callbackFragment.changeFragment();
88 }
89 }
90 });
91 return view;
92 }
93
94 public void
95 setCallbackFragment(CallbackFragment
96 callbackFragment) {
97 this.callbackFragment = callbackFragment;
98 }
99 }

activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayout
3 xmlns:android="http://schemas.android.com/apk/res/
4 android"
5 xmlns:app="http://schemas.android.com/apk/res-
6 auto"
7 xmlns:tools="http://schemas.android.com/tools"
8 android:layout_width="match_parent"
9 android:layout_height="match_parent"
10 tools:context=".MainActivity">
11
12 <FrameLayout
13 android:layout_width="match_parent"
14 android:layout_height="match_parent"
15 android:id="@+id/fragmentContainer"/>
16
17 </androidx.constraintlayout.widget.ConstraintLayout
18 >

login_fragment.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayou
3 t xmlns:android="http://schemas.android.com/apk
4 /res/android"
5 xmlns:app="http://schemas.android.com/apk/res
6 -auto"
7 xmlns:tools="http://schemas.android.com/tools
8 " android:layout_width="match_parent"
9
10 android:layout_height="match_parent">
11
12 <View
13 android:id="@+id/topView"
14 android:layout_width="0dp"
15 android:layout_height="150dp"
16 android:background="@color/purple_500"
17 app:layout_constraintEnd_toEndOf="parent"
18 app:layout_constraintStart_toStartOf="pare
19 nt"
20 app:layout_constraintTop_toTopOf="parent"
21 />
22
23 <View
24 android:id="@+id/view5"
25 android:layout_width="0dp"
26 android:layout_height="100dp"
27 android:background="@drawable/ic_wave__3_"
28 app:layout_constraintEnd_toEndOf="parent"
29 app:layout_constraintStart_toStartOf="pare
30 nt"
31 app:layout_constraintTop_toBottomOf="@+id/
32 topView" />
33
34 <ImageView
35 android:id="@+id/imageView5"
36 android:layout_width="91dp"
37 android:layout_height="94dp"
38 android:layout_marginTop="32dp"
39 android:layout_marginEnd="16dp"
40 android:contentDescription="TOP ICON"
41 app:layout_constraintEnd_toEndOf="parent"
42 app:layout_constraintTop_toTopOf="parent"
43 app:srcCompat="@drawable/ic_baseline_perso
44 n_outline_24" />
45
46 <TextView
47 android:id="@+id/topText"
48 android:layout_width="0dp"
49 android:layout_height="wrap_content"
50 android:layout_marginStart="32dp"
51 android:layout_marginTop="56dp"
52 android:text="Masuk"
53 android:textColor="@android:color/white"
54 android:textSize="30sp"
55 android:textStyle="bold"
56 app:layout_constraintEnd_toStartOf="@+id/i
57 mageView5"
58 app:layout_constraintHorizontal_bias="0.0"
59 app:layout_constraintStart_toStartOf="@+id
60 /topView"
61 app:layout_constraintTop_toTopOf="parent"
62 />
63
64 <EditText
65 android:id="@+id/etUserName"
66 android:layout_width="0dp"
67 android:layout_height="wrap_content"
68 android:layout_marginStart="32dp"
69 android:layout_marginEnd="32dp"
70 android:background="@drawable/round_border
71 "
72 android:drawableStart="@drawable/ic_email"
73 android:drawablePadding="16dp"
74 android:ems="10" android:hint="Username"
75 android:inputType="textPersonName"
76 android:padding="16dp"
77 app:layout_constraintEnd_toEndOf="parent"
78 app:layout_constraintStart_toStartOf="pare
79 nt"
80 app:layout_constraintTop_toBottomOf="@+id/
81 view5" />
82
83 <EditText
84 android:id="@+id/etPassword"
85 android:layout_width="0dp"
86 android:layout_height="wrap_content"
87 android:layout_marginStart="32dp"
88 android:layout_marginTop="16dp"
89 android:layout_marginEnd="32dp"
90 android:background="@drawable/round_borde
100 "
101 android:drawableStart="@drawable/ic_lock"
102 android:drawablePadding="16dp"
103 android:ems="10"
104 android:hint="Password"
105 android:inputType="textPassword"
106 android:padding="16dp"
107 app:layout_constraintEnd_toEndOf="parent"
108 app:layout_constraintStart_toStartOf="pare
109 nt"
110 app:layout_constraintTop_toBottomOf="@+id
111 etUserName" />
112
113 <Button
114 android:id="@+id/btnLogin"
115 android:layout_width="0dp"
116 android:layout_height="wrap_content"
117 android:layout_marginStart="32dp"
118 android:layout_marginEnd="32dp"
119 android:background="@drawable/round_bg"
120 android:text="Login"
121 android:textColor="@color/white"
122 android:textSize="18sp"
123 android:textStyle="bold"
124 app:layout_constraintBottom_toBottomOf="pa
125 rent"
126 app:layout_constraintEnd_toEndOf="parent"
127 app:layout_constraintHorizontal_bias="0.0"
128 app:layout_constraintStart_toStartOf="pare
129 nt"
130 app:layout_constraintTop_toBottomOf="@+id/
131 forgotPassword"
132 app:layout_constraintVertical_bias="0.13"
133 />
134
135 <TextView
136 android:id="@+id/forgotPassword"
137 android:layout_width="wrap_content"
138 android:layout_height="wrap_content"
139 android:layout_marginStart="32dp"
140 android:layout_marginTop="16dp"
141 android:layout_marginEnd="32dp"
142 android:text="Lupa Password"
143 android:textColor="@color/purple_500"
144 android:textSize="18sp"
145 android:textStyle="bold"
146 app:layout_constraintBottom_toBottomOf="pa
147 rent"
148 app:layout_constraintEnd_toEndOf="parent"
149 app:layout_constraintHorizontal_bias="0.49
150 7"
151 app:layout_constraintStart_toStartOf="pare
152 nt"
153 app:layout_constraintTop_toBottomOf="@+id/
154 linearLayout2"
155 app:layout_constraintVertical_bias="0.06"
156 />
157
158 <TextView android:id="@+id/textView7"
159 android:layout_width="wrap_content"
160 android:layout_height="wrap_content"
161 android:layout_marginTop="15dp"
162 android:text="atau"
163 app:layout_constraintBottom_toBottomOf="pa
164 rent"
165 app:layout_constraintEnd_toEndOf="parent"
166 app:layout_constraintHorizontal_bias="0.49
167 8"
168 app:layout_constraintStart_toStartOf="pare
169 nt"
170 app:layout_constraintTop_toBottomOf="@+id/
171 etPassword"
172 app:layout_constraintVertical_bias="0.0"
173 />
174
175 <LinearLayout
176 android:id="@+id/linearLayout2"
177 android:layout_width="0dp"
178 android:layout_height="20dp"
179 android:layout_marginStart="32dp"
180 android:layout_marginTop="10dp"
181 android:layout_marginEnd="32dp"
182 android:orientation="horizontal"
183 app:layout_constraintEnd_toEndOf="parent"
184 app:layout_constraintStart_toStartOf="pare
185 nt"
186 app:layout_constraintTop_toBottomOf="@+id/
187 textView7">
188
189 <ImageView
190 android:id="@+id/googleLogin"
191 android:layout_width="wrap_content"
192 android:layout_height="wrap_content"
193 android:layout_weight="1"
194 android:contentDescription="google
195 icon"
196 app:srcCompat="@drawable/google" />
197
198 <ImageView android:id="@+id/yahoologin"
199 android:layout_width="wrap_content"
200 android:layout_height="wrap_content"
201 android:layout_weight="1"
202 android:contentDescription="yahoo icon"
203 app:srcCompat="@drawable/yahoo" />
204 </LinearLayout>
205
206 <TextView
207 android:id="@+id/daftar"
208 android:layout_width="wrap_content"
209 android:layout_height="wrap_content"
210 android:layout_centerHorizontal="true"
211 android:layout_centerVertical="true"
212 android:layout_marginStart="32dp"
213 android:layout_marginTop="16dp"
214 android:layout_marginEnd="32dp"
215 android:text="Daftar"
216 android:textColor="@color/purple_500"
217 android:textSize="18sp"
218 android:textStyle="bold"
219 app:layout_constraintBottom_toBottomOf="pa
220 rent"
221 app:layout_constraintEnd_toEndOf="parent"
222 app:layout_constraintStart_toStartOf="pare
223 nt"
224 app:layout_constraintTop_toBottomOf="@+id/
225 btnLogin"
226 app:layout_constraintVertical_bias="0.14"
227 />
228
229 </androidx.constraintlayout.widget.ConstraintLay
230 out>

registered_fragment.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayou
3 t xmlns:android="http://schemas.android.com/apk
4 /res/android"
5 xmlns:app="http://schemas.android.com/apk/res
6 -auto"
7 android:layout_width="match_parent"
8 android:layout_height="match_parent">
9
10 <View
11 android:id="@+id/topView"
12 android:layout_width="0dp"
13 android:layout_height="150dp"
14 android:background="@color/purple_500"
15 app:layout_constraintEnd_toEndOf="parent"
16 app:layout_constraintStart_toStartOf="pare
17 nt"
18 app:layout_constraintTop_toTopOf="parent"
19 />
20
21 <View
22 android:id="@+id/view5"
23 android:layout_width="0dp"
24 android:layout_height="100dp"
25 android:background="@drawable/ic_wave__3_"
26 app:layout_constraintEnd_toEndOf="parent"
27 app:layout_constraintStart_toStartOf="pare
28 nt"
29 app:layout_constraintTop_toBottomOf="@+id/
30 topView" />
31
32 <ImageView
33 android:id="@+id/imageView5"
34 android:layout_width="98dp"
35 android:layout_height="91dp"
36 android:layout_marginTop="32dp"
37 android:layout_marginEnd="16dp"
38 android:contentDescription="TOP ICON"
39 app:layout_constraintEnd_toEndOf="parent"
40 app:layout_constraintTop_toTopOf="parent"
41 app:srcCompat="@drawable/ic_account_24" />
42
43 <TextView
44 android:id="@+id/topText"
45 android:layout_width="0dp"
46 android:layout_height="wrap_content"
47 android:layout_marginStart="32dp"
48 android:layout_marginTop="64dp"
49 android:text="Daftar"
50 android:textColor="@android:color/white"
51 android:textSize="30sp"
52 android:textStyle="bold"
53 app:layout_constraintEnd_toStartOf="@+id/i
54 mageView5"
55 app:layout_constraintHorizontal_bias="0.0"
56 app:layout_constraintStart_toStartOf="@+id
57 /topView"
58 app:layout_constraintTop_toTopOf="parent"
59 />
60
61 <EditText
62 android:id="@+id/etUserName"
63 android:layout_width="0dp"
64 android:layout_height="wrap_content"
65 android:layout_marginStart="32dp"
66 android:layout_marginEnd="32dp"
67 android:background="@drawable/round_border
68 "
69 android:drawableStart="@drawable/ic_email"
70 android:drawablePadding="16dp"
71 android:ems="10" android:hint="Username"
72 android:inputType="text"
73 android:padding="16dp"
74 app:layout_constraintEnd_toEndOf="parent"
75 app:layout_constraintStart_toStartOf="pare
76 nt"
77 app:layout_constraintTop_toBottomOf="@+id/
78 view5" />
79 <EditText
80 android:id="@+id/etEmail"
81 android:layout_width="0dp"
82 android:layout_height="wrap_content"
83 android:layout_marginStart="32dp"
84 android:layout_marginTop="16dp"
85 android:layout_marginEnd="32dp"
86 android:background="@drawable/round_border
87 "
88 android:drawableStart="@drawable/ic_lock"
89 android:drawablePadding="16dp"
90 android:ems="10" android:hint="Email"
100 android:inputType="textEmailAddress"
101 android:padding="16dp"
102 app:layout_constraintEnd_toEndOf="parent"
103 app:layout_constraintStart_toStartOf="pare
104 nt"
105 app:layout_constraintTop_toBottomOf="@+id/
106 etUserName" />
107
108 <EditText
109 android:id="@+id/etPassword"
110 android:layout_width="0dp"
111 android:layout_height="wrap_content"
112 android:layout_marginStart="32dp"
113 android:layout_marginTop="16dp"
114 android:layout_marginEnd="32dp"
115 android:background="@drawable/round_border
116 "
117 android:drawableStart="@drawable/ic_lock"
118 android:drawablePadding="16dp"
119 android:ems="10" android:hint="Password"
120 android:inputType="textPassword"
121 android:padding="16dp"
122 app:layout_constraintEnd_toEndOf="parent"
123 app:layout_constraintStart_toStartOf="pare
124 nt"
125 app:layout_constraintTop_toBottomOf="@+id/
126 etEmail" />
127
128 <LinearLayout android:id="@+id/layoutradio"
129 android:layout_width="match_parent"
130 android:layout_height="wrap_content"
131 android:layout_marginLeft="40dp"
132 android:layout_marginRight="40dp"
133 android:orientation="horizontal"
134 app:layout_constraintTop_toBottomOf="@+id/
135 etPassword">
136
137 <RadioGroup
138 android:id="@+id/radiogroup"
139 android:layout_width="match_parent"
140 android:layout_height="match_parent"
141 android:orientation="horizontal">
142
143 <RadioButton android:id="@+id/Pria"
144 android:layout_width="155dp"
145 android:layout_height="wrap_content"
146 android:layout_marginLeft="10dp"
147 android:layout_marginTop="10dp"
148 android:paddingLeft="15dp"
149 android:text="Pria"
150 android:buttonTint="@color/purple_50
151 0"/>
152 app:layout_constraintEnd_toEndOf="pa
153 rent"
154 app:layout_constraintHorizontal_bias
155 ="0.17
156 2"
157 app:layout_constraintStart_toStartOf
158 ="pare
159 nt"
160 app:layout_constraintTop_toBottomOf=
161 "@+id/
162 etPassword" />
163
164 <RadioButton
165 android:id="@+id/Wanita"
166 android:layout_width="155dp"
167 android:layout_height="wrap_content"
168 android:layout_marginLeft="10dp"
169 android:layout_marginTop="10dp"
170 android:paddingLeft="15dp"
171 android:text="Wanita"
172 android:buttonTint="@color/purple_50
173 0"/>
174 app:layout_constraintEnd_toEndOf="pa
175 rent"
176 app:layout_constraintHorizontal_bias
177 ="0.677"
178 app:layout_constraintStart_toEndOf="
179 @+id/Pria"
180 app:layout_constraintTop_toBottomOf=
181 "@+id/etPassword" />
182 </RadioGroup>
183 </LinearLayout>
184
185 <CheckBox
186 android:id="@+id/checkBox5"
187 android:layout_width="wrap_content"
188 android:layout_height="wrap_content"
189 android:padding="10dp" android:text="Anda
190 setuju dengan persyaratan perusahaan kami"
191 android:buttonTint="@color/purple_500"
192 app:layout_constraintEnd_toEndOf="parent"
193 app:layout_constraintStart_toStartOf="pare
194 nt"
195 app:layout_constraintTop_toBottomOf="@+id/
196 layoutradio" />
197
198 <Button
199 android:id="@+id/btnRegistered"
200 android:layout_width="0dp"
201 android:layout_height="wrap_content"
202 android:layout_marginStart="32dp"
203 android:layout_marginTop="22dp"
204 android:layout_marginEnd="32dp"
205 android:background="@drawable/round_bg"
206 android:text="Daftar"
207 android:textColor="@color/white"
208 android:textSize="18sp"
209 android:textStyle="bold"
210 android:visibility="visible"
211 app:layout_constraintBottom_toBottomOf="pa
212 rent"
213 app:layout_constraintEnd_toEndOf="parent"
214 app:layout_constraintHorizontal_bias="1.0"
215 app:layout_constraintStart_toStartOf="pare
216 nt"
217 app:layout_constraintTop_toBottomOf="@+id/
218 etPassword"
219 app:layout_constraintVertical_bias="0.585"
220 />
221
222 </androidx.constraintlayout.widget.ConstraintLayo
223 ut>

C. Screenshot
a. Fragment ImageView

Tampilan awal saat device dinyalakan pertama kali


Tampilan saat tombol Fragment #1 ditekan

Tampilan saat tombol Fragment #2 ditekan


b. Fragment Form

Tampilan pertama saat device dinyalakan.(belum mendaftar)


Tampilan saat ingin melakukan pendaftaran.

Tampilan saat ingin login.


D. Penjelasan

Pertama, untuk program yang Fragment ImageView ini. Jadi pada kelas
MainActivity.java berfungsi untuk memanggil layout activity_main.xml yang
dimana di dalam activity_main.xml tersebut, terdapat FrameLayout yang akan
menjadi tempat untuk meletakkan fragmentnya nanti. Kemudian juga terdapat
2 Button yang di mana masing masing button ini berfungsi untuk menampilkan
ImageView-nya. Saat button Fragment #1 ditekan, maka akan muncul hasil
ImageView berupa gambar seperti yang bisa dilihat pada screenshot diatas dan
juga sama dengan saat button Fragment #2 ditekan, maka ImageView 1 akan
otomatis berubah menjadi ImageView 2 berupa gambar lainnya seperti pada
screenshot diatas.

Selanjutnya kita masuk ke program kedua yakni Fragement Form. Pada


program ini, pertama terdapat kelas MainActivity.java yang berfungsi untuk
memanggil layout activity_main.xml yang di dalamnya terdapat FrameLayout
yang akan berfungsi sebagai tempat untuk meletakkan fragment-nya nanti.
Kemudian dalam MainActivity.java juga akan melakukan pemanggilan
method addFragment() yang berfungsi untuk menampilkan fragment login.
Pada fragment ini nantinya pengguna dapat memasukkan username dan
password. Namun karena di awal ini pengguna belum memiliki akun alias
belum mendaftar, maka pengguna belum bisa login tentunya dan bila pengguna
menekan tombol login namun belum memasukkan username dan password,
maka kaan muncul pop-up “Error” seperti pada screenshot di atas. Oleh karena
itu, pengguna bisa terlebih dahulu mendaftar dengan menekan tombol Daftar
yang nanti akan melakukan pemanggilan method changeFragment yang
berfungsi untuk melakukan perpindahan fragment yakni dari fragment login ke
fragment register. Pada fragment register ini, pengguna dapat mendaftarkan
username baru, email dan password mereka lalu memilih jenis kelamin antara
Pria atau Wanita. Kemudian juga ada button Checkbox yang dimana berupa
persetujuan akan syarat dan ketentuan dari perusahaan. Jika semua sudah
selesai, maka tinggal tekan tombol Daftar dan nanti akan muncul pop up
“Registered” yang menandakan registrasi / pendaftaran akun baru berhasil.
Semua data yang pengguna masukkan ke dalam EditText ini akan disimpan di
dalam sharedPreferences. Karena pada kasus ini digunakan implementasi
backstack fragment, maka untuk kembali ke Fragment login tersebut ,
pengguna hanya perlu menekan tombol back/kembali pada device androidnya.
Akhirnya pengguna sudah bisa melakukan aktifitas login dengan memasukkan
username dan password yang sebelumnya sudah didaftarkan. Jika username
dan password yang dimasukkan sudah benar dan sesuai, maka akan muncul
pop-up “Login” seperti pada screenshot diatas yang menandakan user berhasil
login ke dalam system. Sebaliknya, bila salah satu ada yang salah, maka pop-
upnya akan muncul “Error”.
KESIMPULAN

Kesimpulan Part 1

Activity adalah salah satu komponen yang ada pada Android Studio yang
berfungsi untuk menampilkan user interface (UI) dari aplikasi yang akan dibuat,
biasanya diletakkan pada “setcontentview”. Selain itu, activity juga digunakan untuk
melakukan berbagai kegiatan yang diperlukan di dalam aplikasi tersebut seperti
berpindah dari satu tampilan ke tampilan lainnya, menjalankan program lain, dan
hal-hal lainnya. Activity tidak hidup selamanya, dia bisa diciptakan (create) dan
dihancurkan (destroy). Activity memiliki siklus hidup (lifecycle) yang merupakan
kondisi yang akan dialami saat diciptakan sampai dihancurkan. Pada lifecycle,
terdapat 7 activity. Pertama adalah fungsi onCreate() yang merupakan kondisi awal
saat activity baru diciptakan dan biasanya dilakukan inisialisasi pada tahap ini,
misalnya memanggail setContentView() untuk membaca layout, membaca View.
Kedua adalah fungsi onStart(). Pada tahap ini, activity sudah dimulai tapi belum bisa
berinteraksi. Ketiga adalah fungsi onResume() yang pada fungsi ini activity sudah
terlihat dan pengguna sudah dapat berinteraksi. Selain itu, fungsi ini juga bekerja saat
activity dibuka kembali, biasanya dieksekusi setelah onPause(). Keempat adalah
onPause() yang merupakan kebalikan dari onResume(). Disini, activity sudah akan
bersiap-siap meninggalkan layar (masih terlihat) dan sudah tidak berinteraksi dengan
pengguna. Kelima adalah onStop() yang adalah kebalikan dari onStart(). Pada tahap
ini, activity sudah tidak terlihat dan biasanya juga akan bekerja ketika kita melakukan
undo untuk pekerjaan yang dilakukan di dalam onStart(). Keenam adalah
onRestart() yang dipanggil pada saat activity sudah melalui onStop() namun akan
diaktifkan lagi oleh pengguna. Terakhir adaah onDestroy() yang sesuai dengan
namanya adalah kebalikan dari onCreate(). Tahapan ini terpanggil karena memanggil
method finish() atau karena activity dihancurkan oleh memori karena memori itu
sendiri membutuhkan space lebih. Di dalam fungsi onDestroy() biasanya dilakukan
pembersihan proses-proses yang ada di belakang layer (background process).

Kemudian untuk fungsi dari activity juga sebagai komponen pada aplikasi
android yang menampilkan dan mengatur halaman aplikasi sebagai tempat interaksi
antara pengguna dengan aplikasi, seperti membuat panggilan telepon, mengambil
foto/ merekam video, mengirim pesan singkat/sms, dsb. Sebuah activity juga
berfungsi mengatur satu halaman user interface aplikasi sehingga jika sebuah
aplikasi Android memiliki beberapa halaman user interface yang saling berinteraksi,
berarti aplikasi tersebut memiliki beberapa activity yang saling berinteraksi.

Kesimpulan Part 2

Layout adalah suatu tampilan tata letak pada Android Studio untuk mengatur
penempatan text/gambar yang sudah terkonsep. Jadi layout adalah bagian terpenting
untuk memperindah tampilan pada aplikasi yang dibuat sehingga nyaman di lihat
bagi user. Semua elemen pada layout dibuat menggunakan hirarki objek View dan
ViewGroup. View biasanya menggambar sesuatu yang pengguna bisa melihat dan
berinteraksi dengannya, sedangkan ViewGroup adalah container yang tidak terlihat
yang menentukan struktur layout untuk View dan objek ViewGroup lainnya. Button
merupakan salah satu widget yang memiliki fungsi untuk melakukan perintah
tertentu. Button terdiri dari teks dan icon. Text merupakan salah satu widget yang
berfungsi untuk menampilkan teks pada aplikasi android. Dalam widget ini terdapat
dua elemen di dalamnya yaitu TextView dan EditText. Contoh dari layout sendiri
yakni seperti Linear Layout, Relative Layout dan Constraint Layout. Kemudian
contoh dari Button sendiri adalah seperti Radio Button, Checkbox dan Toggle
Button. Contoh dari Text adalah seperti TextView, Plain Text dan Multiline Text.

Kesimpulan Part 3

Fragment pada dasarnya mirip dengan activity. Namun, fragment memiliki


suatu tujuan spesifik di mana fragment dapat dipakai berulang-ulang di lebih dari
satu activity. Activity juga adalah suatu halaman pada pengembangan aplikasi
android yang berfungsi untuk mengatur suatu komponen tampilan (layout.xml), dan
user interaksi atau logic antar komponen(program.java) agar dapat menghubungkan
antara activity satu dengan activity lainya. Activity juga mengelola bagian-bagian
dari user interface (antar muka), yakni Fragment. Kemudian fragment itu sendiri
adalah salah satu komponen antar muka (user interface) yang merupakan sebuah
bagian dari activity atau dapat disebut dengan nama Sub-Activity. Satu Activity bisa
mengelola beberapa fragment . Jadi kesimpulannya adalah bahwasanya fragment
tidak bisa hidup atau berdiri sendiri(standalone) tanpa adanya minimal 1 activity dan
activity dapat memuat banyak fragment, namun yang pasti keduanya digunakan
untuk keperluan user inteface pada Aplikasi Android.

Anda mungkin juga menyukai