Disini saya membuat aplikasi yang sederhana dimana user / pengguna aplikasi ini bisa login dan mengecek jadwal kuliah kalian pilihan si memang banyak tapi nammanya juga aplkasi sederhana jadi cuma 1 aja yang berfungsi hehehe..
soo dibawah ini source code'a ya guyss...
semoga bermanfaat 🙏🙏
<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"
>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Form
Login"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User
Name" />
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User
Name" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout3"
>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Login"
/>
<Button
android:id="@+id/tutupButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tutup"
/>
</LinearLayout>
</RelativeLayout>
Activity Menu_main.xml
<menu
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_datapribadi"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Data Pribadi"/>
<item
android:id="@+id/action_jadwalkuliah"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Jadwal Kuliah"/>
<item
android:id="@+id/action_keuangan"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Keuangan"/>
<item
android:id="@+id/action_rangkumannilai"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Rangkuman Nilai"/>
<item
android:id="@+id/action_logout"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Logout"/>
</menu>
Sekarang kita urus layout user interfacenya, edit file
res/layout activity_main.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: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:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@+id/listViewJadwal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textViewHari"
android:layout_below="@+id/textViewHari" >
</ListView>
</RelativeLayout>
Untuk layout baris pada list view pada directory layout buat file layout
baru dengan nama row_jadwal.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" />
<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="TextView" />
</RelativeLayout>
Buat class baru dengan nama jadwal.java lalu ketikkan
kode berkut
package com.agusharyanto.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;
}
}
Buat Class baru dengan nama Adapter_jadwal.xml lalu ketikan
kode berikut
package com.agusharyanto.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;
}
}
Edit main_activity.java lalu ketikkan
kode berikut
package com.agusharyanto.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","08:00-10:00","Matematika"));
list_jadwal.add(new Jadwal("Senin","10:00-12:00","Agama Islam"));
list_jadwal.add(new Jadwal("Senin","12:00-13:00","Istirahat"));
list_jadwal.add(new Jadwal("Senin","13:00-15:00","Fisika"));
list_jadwal.add(new Jadwal("Selasa","08:00-10:00","Bahaa Indonesia"));
list_jadwal.add(new Jadwal("Selasa","10:00-12:00","Kimia"));
list_jadwal.add(new Jadwal("Selasa","12:00-13:00","Istirahat"));
list_jadwal.add(new Jadwal("Selasa","13:00-15:00","Biologi"));
list_jadwal.add(new Jadwal("Rabu","08:00-10:00","Matematika"));
list_jadwal.add(new Jadwal("Rabu","10:00-12:00","Seni Rupa"));
list_jadwal.add(new Jadwal("Rabu","12:00-13:00","Istirahat"));
list_jadwal.add(new Jadwal("Rabu","13:00-15:00","Bahasa Inggris"));
list_jadwal.add(new Jadwal("Kamis","08:00-10:00","Fisika"));
list_jadwal.add(new Jadwal("Kamis","10:00-12:00","Penjaskes"));
list_jadwal.add(new Jadwal("Kamis","12:00-13:00","Istirahat"));
list_jadwal.add(new Jadwal("Kamis","13:00-15:00","Geografi"));
list_jadwal.add(new Jadwal("Jumat","08:00-10:00","Pemrograman Java"));
list_jadwal.add(new Jadwal("Jumat","10:00-12:00","Pemrograman Android"));
list_jadwal.add(new Jadwal("Jumat","12:00-13:00","Istirahat"));
list_jadwal.add(new Jadwal("Jumat","13:00-15:00","Logika Algoritma"));
}
@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);
}
}
Saatnya Run Projectnya
1.
User name
2.
Password
3.
Log in
4.
Jadwal kuliah
5.
Pilih hari
6.
hasil