“Membuat Aplikasi Mengenal Rambu Lalu Lintas"
Assalamulaikum, Wr. Wb.
Pada laporan kali ini saya akan membuat aplikasi Input data Array. Disini saya membuat Aplikasi android dengan menggunankan ADT.
- Membuat projek baru di editor yang akan kita gunakan seperti ADT, Android Studio, Dll.
File > New > Android Application Project dan beri nama pada aplikasi yang akan kita buat, contoh “Input Data”
- Disni file xml dengan nama “awal” dan file java “AwalActivity”
Awal.xml:
<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:background="@drawable/bgr"
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=".AwalActivity" >
<Button
android:id="@+id/masuk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg"
/>
</RelativeLayout>
Hasil :
Kita buat tampilan menu
Menu.xml
<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:background="@drawable/back"
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=".MenuActivity" >
<Button
android:id="@+id/help"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_above="@+id/about"
android:layout_centerHorizontal="true"
android:background="@drawable/help" />
<Button
android:id="@+id/about"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="86dp"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/help"
android:background="@drawable/about" />
<Button
android:id="@+id/mulai"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_above="@+id/help"
android:layout_marginRight="23dp"
android:layout_toLeftOf="@+id/help"
android:background="@drawable/awal" />
</RelativeLayout>
Hasil:
MenuActivity.java
package com.riski.mengenalrambulalulintas;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MenuActivity extends Activity implements OnClickListener{
Button mulai;
Button help;
Button about;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Button awal = (Button)findViewById(R.id.mulai);
Button help = (Button)findViewById(R.id.help);
Button about = (Button)findViewById(R.id.about);
awal.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent awal = new Intent(MenuActivity. this, MenuaActivity.class);
startActivity(awal);
}
});
help.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent awal = new Intent(MenuActivity. this, HelpActivity.class);
startActivity(awal);
}
});
about.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent awal = new Intent(MenuActivity. this, AboutActivity.class);
startActivity(awal);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
- Menua.xml
<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:background="@drawable/ba"
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=".MenuaActivity" >
<Button
android:id="@+id/satu"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/kiri"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/dua"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/kanan"
android:layout_marginTop="20dp"
android:layout_marginLeft="120dp"
/>
<Button
android:id="@+id/tiga"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/tikungan_ganda"
android:layout_marginTop="20dp"
android:layout_marginLeft="220dp"
/>
<Button
android:id="@+id/empat"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/tikungan_tajam"
android:layout_below="@+id/satu"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/lima"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/tikungan_tajam_ganda"
android:layout_below="@+id/dua"
android:layout_marginTop="30dp"
android:layout_marginLeft="120dp"
/>
<Button
android:id="@+id/enam"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/penyempitan_jalan"
android:layout_below="@+id/tiga"
android:layout_marginTop="30dp"
android:layout_marginLeft="220dp"
/>
<Button
android:id="@+id/tujuh"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/penyempitan_jalan_kanan"
android:layout_below="@+id/empat"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/lapan"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/jembatan"
android:layout_below="@+id/lima"
android:layout_marginTop="30dp"
android:layout_marginLeft="120dp"
/>
<Button
android:id="@+id/sembilan"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/turunan_lantai"
android:layout_below="@+id/enam"
android:layout_marginTop="30dp"
android:layout_marginLeft="220dp"
/>
<Button
android:id="@+id/sepuluh"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/turunan_curam"
android:layout_below="@+id/tujuh"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/sebelas"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/jalan_licin"
android:layout_below="@+id/lapan"
android:layout_marginTop="30dp"
android:layout_marginLeft="120dp"
/>
<Button
android:id="@+id/duabelas"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/cekungan"
android:layout_below="@+id/lapan"
android:layout_marginTop="30dp"
android:layout_marginLeft="220dp"
/>
<Button
android:id="@+id/tigabelas"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/jalan_cembung"
android:layout_below="@+id/sepuluh"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/empatbelas"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/jalan_bergelombang"
android:layout_below="@+id/sebelas"
android:layout_marginTop="30dp"
android:layout_marginLeft="120dp"
/>
<Button
android:id="@+id/limabelas"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/lontaran_kecil"
android:layout_below="@+id/duabelas"
android:layout_marginTop="30dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
Hasil:
MenuaActivity.java
package com.riski.mengenalrambulalulintas;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MenuaActivity extends Activity implements OnClickListener{
Button satu;
Button dua;
Button tiga;
Button empat;
Button lima;
Button enam;
Button tujuh;
Button delapan;
Button sembilan;
Button sepuluh;
Button seblas;
Button duablas;
Button tigablas;
Button empatblas;
Button limablas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menua);
Button satu = (Button)findViewById(R.id.satu);
satu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, Satu.class);
startActivity(satu);
}
});
Button dua = (Button)findViewById(R.id.dua);
dua.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, DuaActivity.class);
startActivity(satu);
}
});
Button tiga = (Button)findViewById(R.id.tiga);
tiga.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, TigaActivity.class);
startActivity(satu);
}
});
Button empat = (Button)findViewById(R.id.empat);
empat.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, EmpatActivity.class);
startActivity(satu);
}
});
Button lima = (Button)findViewById(R.id.lima);
lima.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, LimaActivity.class);
startActivity(satu);
}
});
Button enam = (Button)findViewById(R.id.enam);
enam.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, EnamActivity.class);
startActivity(satu);
}
});
Button tujuh = (Button)findViewById(R.id.tujuh);
tujuh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, TujuhActivity.class);
startActivity(satu);
}
});
Button delapan = (Button)findViewById(R.id.lapan);
delapan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, DelapanActivity.class);
startActivity(satu);
}
});
Button sembilan = (Button)findViewById(R.id.sembilan);
sembilan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, SembilanActivity.class);
startActivity(satu);
}
});
Button sepuluh = (Button)findViewById(R.id.sepuluh);
sepuluh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, SepuluhActivity.class);
startActivity(satu);
}
});
Button seblas = (Button)findViewById(R.id.sebelas);
seblas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, SeblasActivity.class);
startActivity(satu);
}
});
Button duablas = (Button)findViewById(R.id.duabelas);
duablas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, DuablasActivity.class);
startActivity(satu);
}
});
Button tigablas = (Button)findViewById(R.id.tigabelas);
tigablas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, TigablasActivity.class);
startActivity(satu);
}
});
Button empatblas = (Button)findViewById(R.id.empatbelas);
empatblas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, EmpatblasActivity.class);
startActivity(satu);
}
});
Button limablas = (Button)findViewById(R.id.limabelas);
limablas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent satu = new Intent(MenuaActivity. this, LimablasActivity.class);
startActivity(satu);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menua, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Help.xml
<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:background="@drawable/helpb"
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=".HelpActivity" >
</RelativeLayout>
Hasil:
About.xml
<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:background="@drawable/tentang"
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=".AboutActivity" >
</RelativeLayout>
Hasil:
Hasil Running Aplikasi :