Langkah-langkah membuat nama project1:
1. Membuat Project1 dengan membuat nama aplikasi
2. Menentukan lokasi penyimpanan aplikasi yang telah dibuat.
3. Mengubah Gambar Logo Aplikasi
4. Memilih Blank Activity guna dapat mengedit action bar
5. Tampilan Awal Aplikasi Pada Eclipse
Langkah-langkah
memasukkan kode kedalam eclipse dan hasil
tampilan awal aplikasi
6. Siapkan menu untuk aplikasi JadwalPelajaran, masuk directory res/menu lalu edit main.xml
Dengan
koding sebagai berikut :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+id/action_senin"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Senin"/>
<item
android:id="@+id/action_selasa"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Selasa"/>
<item
android:id="@+id/action_rabu"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Rabu"/>
<item
android:id="@+id/action_kamis"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Kamis"/>
<item
android:id="@+id/action_jumat"
android:orderInCategory="100" android:showAsAction="never"
android:title="Jumat"/>
</menu>
7. Kemudian melakukan pengeditan pada layout user interfacenya, caranya
edit file res/layout activity_main.xml
Dengan Koding seperti
berikut :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/background"
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=".MainActivity" >
<TextView
android:id="@+id/textViewHari"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ListView
android:id="@+id/listViewJadwal"
android:textDirection="firstStrong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textViewHari"
android:layout_below="@+id/textViewHari" >
</ListView>
</RelativeLayout>
8. Pada directory res/layout buat file layout baru dengan
nama row_jadwal.xml caranya dengan klik pada
res>layout, klik kanan pada layout > new > pilih Android XML File dan
muncul tampilan
Edit Kode pada directory res/layout/row_jadwal.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:textSize="25sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textViewRowJam"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="" />
<TextView
android:id="@+id/textViewRowPelajaran"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:layout_toRightOf="@+id/textViewRowJam"
android:text="" />
</RelativeLayout>
9. Buat class baru dengan nama Jadwal.java, dengan cara pilih src/com.xf.jadwalpelajaran > klik kanan
> new > pilih class akan keluar
tampilan
Edit Kode berikut:
package
com.xf.jadwalpelajaran;
public class
Jadwal {
public
String hari="";
public
String jam="";
public
String pelajaran="";
public
Jadwal (String pday, String ptime, String plesson){
this.hari =
pday;
this.jam =
ptime;
this.pelajaran =
plesson;
}
}
10. Buat Class baru lagi dengan nama AdapterJadwal.java
Edit kode berikut :
package com.xf.jadwalpelajaran;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class AdapterJadwal extends
ArrayAdapter<Jadwal>{
private
Activity activity;
private
ArrayList<Jadwal> lJadwal;
private
static LayoutInflater inflater = null;
public AdapterJadwal (Activity activity, int
textViewResourceId, ArrayList<Jadwal> al_Jadwal) {
super(activity, textViewResourceId, al_Jadwal);
try
{
this.activity = activity;
this.lJadwal = al_Jadwal;
inflater = (LayoutInflater)
activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
catch (Exception e) {
}
}
public
int getCount() {
return lJadwal.size();
}
public
long getItemId(int position) {
return position;
}
public
static class ViewHolder {
public TextView jam;
public TextView pelajaran;
}
public
View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
try
{
if (convertView == null) {
vi =inflater.inflate(R.layout.row_jadwal, null);
holder = new ViewHolder();
holder.jam = (TextView) vi.findViewById(R.id.textViewRowJam);
holder.pelajaran = (TextView)
vi.findViewById(R.id.textViewRowPelajaran);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.jam.setText(lJadwal.get(position).jam);
holder.pelajaran.setText(lJadwal.get(position).pelajaran);
}
catch (Exception e) {
}
return vi;
}
kemudian ketikkan kode berikut :
package
com.xf.jadwalpelajaran;
import
java.util.ArrayList;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.MenuItem;
import
android.widget.ListView;
import
android.widget.TextView;
public class
MainActivity extends Activity {
ArrayList <Jadwal> list_jadwal = new ArrayList<Jadwal>();
TextView
tvhari;
ListView
listviewjadwal ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvhari
= (TextView) findViewById(R.id.textViewHari);
listviewjadwal = (ListView)
findViewById(R.id.listViewJadwal);
initData();
}
public void initData() {
list_jadwal.add(new
Jadwal("Senin","07:30-10:00","Upacara"));
list_jadwal.add(new
Jadwal("Senin","08:15-09:00","Fisika"));
list_jadwal.add(new
Jadwal("Senin","09:00-09:45","Fisika"));
list_jadwal.add(new
Jadwal("Senin","09:45-10:00","Istirahat"));
list_jadwal.add(new
Jadwal("Senin","10:00-10:45","Sistem Digital"));
list_jadwal.add(new
Jadwal("Senin","10:45-11:30","Sistem Digital"));
list_jadwal.add(new
Jadwal("Senin","11:30-12:15","Sistem Digital"));
list_jadwal.add(new
Jadwal("Senin","12:15-13:00","Istirahat"));
list_jadwal.add(new
Jadwal("Senin","13:00-13:45","Sistem Komputer"));
list_jadwal.add(new
Jadwal("Senin","13:45-14:30","Sistem Komputer"));
list_jadwal.add(new
Jadwal("Senin","14:30-15:15","PD"));
list_jadwal.add(new
Jadwal("Senin","15:15-16:00","PD"));
list_jadwal.add(new
Jadwal("Selasa","07:30-08:15","Wirausaha"));
list_jadwal.add(new
Jadwal("Selasa","08:15-09:00","Wirausaha"));
list_jadwal.add(new
Jadwal("Selasa","09:00-09:45","SI"));
list_jadwal.add(new
Jadwal("Selasa","09:45-10:00","Istirahat"));
list_jadwal.add(new
Jadwal("Selasa","10:00-10:45","SI"));
list_jadwal.add(new
Jadwal("Selasa","10:45-11:30","Bahasa Inggris"));
list_jadwal.add(new
Jadwal("Selasa","11:30-12:15","Bahasa Inggris"));
list_jadwal.add(new
Jadwal("Selasa","12:15-13:00","Istirahat"));
list_jadwal.add(new
Jadwal("Selasa","13:00-13:45","Mulok"));
list_jadwal.add(new
Jadwal("Selasa","13:45-14:30","Mulok"));
list_jadwal.add(new
Jadwal("Selasa","14:30-15:15","Matematika"));
list_jadwal.add(new
Jadwal("Selasa","15:15-16:00","Matematika"));
list_jadwal.add(new Jadwal("Rabu","07:30-08:15","MicroProsesor"));
list_jadwal.add(new
Jadwal("Rabu","08:15-09:00","MicroProsesor"));
list_jadwal.add(new
Jadwal("Rabu","09:00-09:45","Perakitan & Perawatan
Komputer"));
list_jadwal.add(new
Jadwal("Rabu","09:45-10:00","Istirahat"));
list_jadwal.add(new
Jadwal("Rabu","10:00-10:45","Perakitan & Perawatan
Komputer"));
list_jadwal.add(new
Jadwal("Rabu","10:45-11:30","Pelajaran Agama
Islam"));
list_jadwal.add(new
Jadwal("Rabu","11:30-12:15","Pelajaran Agama
Islam"));
list_jadwal.add(new Jadwal("Rabu","12:15-13:00","Istirahat"));
list_jadwal.add(new
Jadwal("Rabu","13:00-13:45","Pelajaran Agama
Islam"));
list_jadwal.add(new
Jadwal("Rabu","13:45-14:30","Matematika"));
list_jadwal.add(new
Jadwal("Rabu","14:30-15:15","Matematika"));
list_jadwal.add(new Jadwal("Rabu","15:15-16:00","BudiPekerti"));
list_jadwal.add(new
Jadwal("Kamis","07:30-08:10","Bahasa
Indonesia"));
list_jadwal.add(new
Jadwal("Kamis","08:10-08:50","Bahasa
Indonesia"));
list_jadwal.add(new
Jadwal("Kamis","08:50-09:30","Olahraga"));
list_jadwal.add(new
Jadwal("Kamis","09:30-09:45","Istirahat"));
list_jadwal.add(new
Jadwal("Kamis","09:45-10:20","Olahraga"));
list_jadwal.add(new
Jadwal("Kamis","10:20-11:05","Seni Budaya"));
list_jadwal.add(new
Jadwal("Kamis","11:05-11:45","Seni Budaya"));
list_jadwal.add(new
Jadwal("Kamis","11:45-12:25","Perakitan &
Perawatan Komputer"));
list_jadwal.add(new
Jadwal("Kamis","12:25-13:10","Istirahat"));
list_jadwal.add(new
Jadwal("Kamis","13:10-13:50","Perakitan &
Perawatan Komputer"));
list_jadwal.add(new
Jadwal("Kamis","13:50-14:30","JARDAS"));
list_jadwal.add(new
Jadwal("Kamis","14:30-15:10","JARDAS"));
list_jadwal.add(new
Jadwal("Kamis","15:10-15:50","PKN"));
list_jadwal.add(new
Jadwal("Kamis","15:50-16:30","PKN"));
list_jadwal.add(new
Jadwal("Jumat","07:30-08:10","Sisop"));
list_jadwal.add(new
Jadwal("Jumat","08:10-08:50","Sisop"));
list_jadwal.add(new
Jadwal("Jumat","08:50-09:30","Bahasa
Indonesia"));
list_jadwal.add(new
Jadwal("Jumat","09:30-09:45","Istirahat"));
list_jadwal.add(new
Jadwal("Jumat","09:45-10:25","Bahasa
Indonesia"));
list_jadwal.add(new
Jadwal("Jumat","10:25-11:05","JARDAS"));
list_jadwal.add(new
Jadwal("Jumat","11:05-11:45","JARDAS"));
list_jadwal.add(new
Jadwal("Jumat","11:45-14:00","Istirahat"));
list_jadwal.add(new
Jadwal("Jumat","14:00-14:40","OL"));
list_jadwal.add(new
Jadwal("Jumat","14:40-15:20","PERWEB"));
list_jadwal.add(new
Jadwal("Jumat","15:20-16:00","PERWEB"));
list_jadwal.add(new Jadwal("Jumat","16:00-16:40","PERWEB"));
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
//
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return
super.onCreateOptionsMenu(menu);
}
/**
* On
selecting action bar
* */
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
//
Take appropriate action for each action item click
switch (item.getItemId()) {
case
R.id.action_senin:
showJadwal("Senin");
return true;
case
R.id.action_selasa:
// location found
showJadwal("Selasa");
return true;
case
R.id.action_rabu:
showJadwal("Rabu");
return true;
case
R.id.action_kamis:
showJadwal("Kamis");
return true;
case
R.id.action_jumat:
showJadwal("Jumat");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public
void showJadwal(String hari) {
tvhari.setText("Hari " + hari);
ArrayList<Jadwal> jadwal_terpilih = new ArrayList<Jadwal>();
for (int i = 0; i < list_jadwal.size(); i++) {
Jadwal jadwal = list_jadwal.get(i);
if (jadwal.hari.equals(hari)) {
jadwal_terpilih.add(jadwal);
}
}
AdapterJadwal
adapterjadwal = new AdapterJadwal(MainActivity.this, 0,
jadwal_terpilih);
listviewjadwal.setAdapter(adapterjadwal);
}
}
12. Untuk
melihat tampilan res/layout/activity_main.xml
> pilih
“ Graphical Layout “
13.Cara Mengubah Background
Pilih
res/drawable-hdpi > copy gambar background yang telah disediakan ke dalam folder drawable-hdpi seperti gambar
dibawah
Masukan code pada res/layout/activity_main.xml berikut
Akhir dari tampilan background
14. Klik
kanan pada folder JadwalPelajaran
> pilih Run Us >
pilih android application di Eclipse atau ctrl+F11
18. Hasil Jadwal Pelajaran
aku mau nyoba,, smoga berhasil yah!!
BalasHapusone question,,ini bisa dibuat pada elipse (segala eklipse/ merek berbeda kan??)
aplikasi apa dipakai itu mbakbro?
BalasHapusKira2 untuk TA bisa gx iya ?
BalasHapus