Newest Post
Archive for Oktober 2019
Aplikasi Daftar Handphone Dengan ListView Dan Intent Menggunakan Android Studio
Aplikasi Daftar Handphone Dengan ListView Dan Intent Menggunakan Android Studio Aplikasi ini saya buat menggunakan Android Studio. saya akan memberika penjelasan tentang Aplikasi Daftar Handphone Dengan ListView Dan Intent Menggunakan Android Studio dalam rangka memenuhi Tugas Ujian Tengah Semester (UTS).
Judul Project Dan Penjelasan
aplikasi ini adalah aplikasi untuk melihat daftar handphone dan spesifikasi HP, yang menggunkan listview dan intent.
Tampilan Aplikasinya
Tampilan Aplikasi |
langkah - langkah membuat project baru di android studio
- Buka Aplikasi Android Studio
- Buat Project baru dengan memilih template Empty kemudian klik Next
Pemilihan Template |
3. Masukan Nama, Tentukan Lokasi Penyimpanan, Lalu Pilih Minimum API Level. kemudian Finish
Menentukan Nama |
4. Membuat Login.XML
Login XML |
Source Code Login.XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-a
uto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="16dp" android:background="@drawable/log1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#0091EA"> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="?android:attr/selectableItemBackground" android:onClick="loginMasuk" android:text="LOGIN" android:textColor="#FFF" android:textStyle="normal|bold" /> /> </LinearLayout> <EditText android:id="@+id/edittext_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/edittext_password" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_marginStart="3dp" android:layout_marginLeft="3dp" android:layout_marginBottom="9dp" android:fontFamily="monospace" android:hint="Username" android:inputType="textCapWords" android:textSize="30sp" /> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginStart="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="18dp" android:background="#0091EA" android:text="KELVIN CELLULER" android:textAlignment="center" android:textColor="#fff" android:textSize="36sp" android:textStyle="normal|bold" /> <EditText android:id="@+id/edittext_password" style="@style/AppTheme" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginStart="-1dp" android:layout_marginLeft="-1dp" android:fontFamily="monospace" android:hint="Password" android:inputType="textPassword" android:textSize="30sp" /> <ImageView android:id="@+id/imageView" android:layout_width="140dp" android:layout_height="119dp" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginStart="106dp" android:layout_marginLeft="106dp" android:layout_marginTop="86dp" android:src="@drawable/k" tools:srcCompat="@drawable/k" /> </RelativeLayout>
5. Membuat LoginMain.Java
Login Java |
Source Code LoginMain.Java
package com.example.cellulervin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { EditText editText1 ,editText2; String text1 ,text2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().setTitle (" Form Login"); getSupportActionBar().setSubtitle (" KELVIN GUNAWAN"); } public void loginMasuk(View view) { editText1 = (EditText)findViewById(R.id.edittext_username); editText2 = (EditText) findViewById(R.id.edittext_password); text1 = editText1.getText().toString(); text2 = editText2.getText().toString(); if ((text1.contains("Kelvin"))&&((text2.contains("kelvin123")))) { Toast.makeText(this, "Login Sukses", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, KelvinCell.class); startActivity(intent); } else if ((text1.matches("")||text2.matches(""))) /* Atau jika input text 1 dan text 2 kosong */ { //Maka akan menampilkan pesan text toast Toast.makeText(this, "Isikan Username dan Password", Toast.LENGTH_SHORT).show(); } else { //jika kedua kondisi diatas tidak memenuhi Toast.makeText(this, "Login Gagal /Username Password Salah", Toast.LENGTH_SHORT).show(); } } }
Tampilan Dari Form Login
Tampilan Form Login |
ListView Java |
Source Code Kelvincell.java
package com.example.cellulervin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class KelvinCell<position> extends AppCompatActivity { ListView LV; String[] BrandHp = {"SAMSUNG", "APPLE", "ASUS", "OPPO", "VIVO", "XIAOMI", "HUAWEI", "REALME", "ADVAN", "ONEPLUS"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kelvin_cell); LV = (ListView) findViewById(R.id.listView1); ArrayAdapter adapsi = new ArrayAdapter(this, android.R.layout.simple_list_item_1, BrandHp); LV.setAdapter(adapsi); LV.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int itemKe, long arg3) { // TODO Auto-generated method stub String itemText = (String) LV.getItemAtPosition(itemKe); Toast.makeText(getBaseContext(), "Anda Meng Klik " + itemText, Toast.LENGTH_LONG).show(); if (itemText.equals("SAMSUNG")) { Intent I = new Intent(arg0.getContext(), Samsung.class); startActivityForResult(I, 0); } else if (itemText.equals("APPLE")) { Intent Pop = new Intent(arg0.getContext(), Apple.class); startActivityForResult(Pop, 0); } else if (itemText.equals("ASUS")) { Intent Pop = new Intent(arg0.getContext(), Asus.class); startActivityForResult(Pop, 0); } } }); } }
7. Membuat Listview XML
Listview XML |
Source Code XML
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".KelvinCell" > <ListView android:id="@+id/listView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/back2"> android:padding="4dp"> </ListView> </RelativeLayout>
8. Membuat ListHandphone Samsung.java
ListView Dari Samsung |
Source Code Samsung.java
package com.example.cellulervin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class Samsung extends AppCompatActivity { ListView LV; String[] BrandHp = {"SAMSUNG A10", "SAMSUNG A20", "SAMSUNG A30", "SAMSUNG A50", "SAMSUNG A70", "SAMSUNG A80", "SAMSUNG S7", "SAMSUNG S8", "SAMSUNG S9", "SAMSUNG S10"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kelvin_cell); LV = (ListView) findViewById(R.id.listView1); ArrayAdapter adapsi = new ArrayAdapter(this, android.R.layout.simple_list_item_1, BrandHp); LV.setAdapter(adapsi); LV.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int itemKe, long arg3) { // TODO Auto-generated method stub String itemText = (String) LV.getItemAtPosition(itemKe); Toast.makeText(getBaseContext(), "Anda Meng Klik " + itemText, Toast.LENGTH_LONG).show(); if (itemText.equals("SAMSUNG A10")) { Intent I = new Intent(arg0.getContext(), Sa10.class); startActivityForResult(I, 0); } else if (itemText.equals("SAMSUNG A20")) { Intent Pop = new Intent(arg0.getContext(), Sa20.class); startActivityForResult(Pop, 0); } else if (itemText.equals("SAMSUNG A30")) { Intent Pop = new Intent(arg0.getContext(), Apple.class); startActivityForResult(Pop, 0); } } }); } }
9. Membuat List Spesifikasi
ListView Spesifikasi |
Source Code Sa20.XML
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="16dp" android:background="@drawable/back3" android:orientation="vertical" tools:context="Sa20"> <TextView android:id="@+id/getharga" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="5dp" android:text="Harga:" android:textColor="#0629F3" android:textColorHighlight="#F2F2F2" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getos" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="32dp" android:text="OS:" android:textColor="#092CF0" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getchipset" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="58dp" android:text="Chipset:" android:textColor="#0D2FEE" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getgpu" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="82dp" android:text="GPU:" android:textColor="#0A2CE9" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getcpu" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="105dp" android:text="CPU:" android:textColor="#0C2EEE" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getmemory" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="130dp" android:text="MEMORY:" android:textColor="#0D30E9" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/getbattery" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" android:layout_marginTop="154dp" android:text="BATTERY:" android:textColor="#1031E9" android:textSize="15sp" android:textStyle="bold" /> <ImageView android:id="@+id/imageView2" android:layout_width="295dp" android:layout_height="337dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="30dp" android:layout_marginTop="273dp" android:src="@drawable/a20" android:textSize="15sp" android:textStyle="bold" />/> </RelativeLayout>
10. Membuat Java Class dari Sa20
Sa20Java |
Source Code Dari Sa20.java
package com.example.cellulervin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class Sa20 extends AppCompatActivity { private TextView harga, OS, Chipset, GPU, CPU, MEMORY, BATTERY; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sa20); harga = findViewById(R.id.getharga); OS = findViewById(R.id.getos); Chipset = findViewById(R.id.getchipset); GPU = findViewById(R.id.getgpu); CPU = findViewById(R.id.getcpu); MEMORY = findViewById(R.id.getmemory); BATTERY = findViewById(R.id.getbattery); harga.setText("Harga: Rp. 2.015.000"); OS.setText("OS: Android 9.0 (Pie); One UI"); Chipset.setText("Chipset: Exynos 7884 (14 nm)"); GPU.setText("GPU: Mali-G71 MP2"); CPU.setText("CPU: Octa-core (2x1.6 GHz Cortex-A73 & 6x1.35)"); MEMORY.setText("Memory: Storage 32GB , RAM 3GB"); BATTERY.setText("Battery: Non-removable Li-Po 4000 mAh"); } }
maka sudah selesai untuk pembuatan aplikasi listview Handphone ini. Sekarang kita akan masuk ke tahap uji coba atau kita coba Run Aplikasinya.
yang pertama kita akan masuk ke form login
Form Login |
Tampilan Awal |
List Handphone Samsung |
Spesifikasi |
Aplikasi Daftar Handphone Dengan ListView Dan Intent Menggunakan Android Studio
Rabu, 23 Oktober 2019
Posted by kelvin
Tag :// UTS