Belajardengan.com merupakan domain blog lama dari delajardengan.blogspot.com. Mohon kritik dan sarannya untuk perkembangan blog ini.
email: blog.tkx.pnp@gmail.com

Aplikasi Android Client Server Sederhana (Menu Makanan Indonesia)

♠ Posted by Unknown in at 10:58 AM
A.       Pengenalan
Aplikasi  Resep Makanan Indonesia merupa aplikasi pencarian resep menu makanan Indonesia berbasis klien server. Berikut skema aplikasinya:


B.       StrukturDatabase
Database
Nama database : ‘mm’
C.       Struktur Program

A.       Sourcecode dan tampilan Aplikasi
1.      MmActivity.java
package com.mm;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MmActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[8];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
        a[4]=(ImageButton)findViewById(R.id.btn_home2);
        a[5]=(ImageButton)findViewById(R.id.btn_favo2);
        a[6]=(ImageButton)findViewById(R.id.btn_search2);
        a[7]=(ImageButton)findViewById(R.id.btn_prov2);
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
       }
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[4]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[5]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[6]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[7]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                               
                }
}

2.      Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/latar">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:gravity="center_horizontal" android:layout_height="wrap_content">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/bt_home" android:src="@drawable/agt_home" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_favo" android:src="@drawable/e" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_search" android:src="@drawable/c" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_prov" android:src="@drawable/a" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:layout_weight="0.07"></LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/LinearLayout01" android:gravity="center_vertical|center_horizontal" android:layout_height="wrap_content" android:layout_weight="0.13">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_home2" android:src="@drawable/cc" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_favo2" android:src="@drawable/aa" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/LinearLayout03" android:gravity="center_vertical|center_horizontal" android:layout_height="wrap_content" android:layout_weight="0.16">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_search2" android:src="@drawable/dd" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_prov2" android:src="@drawable/bb" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
</LinearLayout>



Gambar tampilan main.xml

3.      Favorit.java
package com.mm;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Favorit extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[4];
                public static int category_id = 3; // kategori yang akan di tampilkan
                public static String config_path="http://10.0.2.2/mm/";
                public static String config_url = config_path+"mm.php";                // link website
                private int num_record=10;        // default jumlah record yang ditampilkan
                private String prov_id[];
                private ListView lv;
                private Button refresh, more;
                private Context ctx = this;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.favorit);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
        lv = (ListView) findViewById(R.id.listView1);
                                refresh = (Button)findViewById(R.id.button1);
                                refresh.setOnClickListener(this);
                                getData();
                                lv.setTextFilterEnabled(true);                   
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
                System.out.println(i);
        }
        lv.setOnItemClickListener(new OnItemClickListener() {                                                                        
                                                @Override
                                                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                                                                long arg3) {
                                                                if(prov_id != null){
                                                                                Toast.makeText(getApplicationContext(),
                                                                                ((TextView) arg1).getText()+" - "+arg2, Toast.LENGTH_SHORT).show();
                                                                                Menuset.id= prov_id[arg2];
                                                                                startActivity(new Intent(ctx, Menuset.class));
                                                                }
                                                }
                                });
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==refresh){
                                                num_record = 10;            // refresh data 10 record pertama
                                                getData();
                                                Toast.makeText(getApplicationContext(),"Refresh Data Success!", Toast.LENGTH_SHORT).show();
                                }
                               
                }
               
                public void getData() {
                                String data[] = { "Tidak Ada Data" };
                                try {
                                                URL url = new URL(config_url + "?f=12&c=" + category_id+"&m="+num_record);
                                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                                DocumentBuilder db = dbf.newDocumentBuilder();
                                                Document doc = db.parse(new InputSource(url.openStream()));
                                                doc.getDocumentElement().normalize();
                                                NodeList nodeList = doc.getElementsByTagName("item");
                                                data = new String[nodeList.getLength()];
                                                prov_id = new String[nodeList.getLength()];
                                                for (int i = 0; i < nodeList.getLength(); i++) {
                                                                Node node = nodeList.item(i);
                                                                Element fstElmnt = (Element) node;
                                                                NodeList nameList = fstElmnt.getElementsByTagName("title");
                                                                Element nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                data[i] = ((Node) nameList.item(0)).getNodeValue();
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("link");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                prov_id[i]= ((Node) nameList.item(0)).getNodeValue();
                                                                                                               
                                                }
                                                if(nodeList.getLength()==0){
                                                                prov_id=null;
                                                }
                                } catch (Exception e) {
                                                // TODO: handle exception
                                }

                                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_list_item_1, data);
                                lv.setAdapter(adapter);
                }
}


4.       Favorit.xml
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    android:orientation=”vertical”
    android:layout_width=”fill_parent”
    android:layout_height=”fill_parent”
    android:weightSum=”1” android:background=”@drawable/latar”>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout1” android:layout_height=”wrap_content” android:gravity=”center_horizontal”>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/bt_home” android:src=”@drawable/agt_home” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_favo” android:src=”@drawable/e” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_search” android:src=”@drawable/c” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_prov” android:src=”@drawable/a” android:layout_height=”wrap_content”></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout2” android:layout_height=”wrap_content” android:weightSum=”1” android:gravity=”center_vertical” android:layout_weight=”0.07”>
        <TextView android:layout_width=”wrap_content” android:textAppearance=”?android:attr/textAppearanceMedium” android:id=”@+id/textView1” android:layout_height=”wrap_content” android:text=”Pilih : “ android:textColor=”#ffffff”></TextView>
        <TextView android:textAppearance=”?android:attr/textAppearanceMedium” android:id=”@+id/textView2” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:text=”Menu” android:textColor=”#ffffff”></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout3” android:layout_height=”wrap_content” android:orientation=”vertical” android:layout_weight=”0.92”>
        <ListView android:layout_width=”match_parent” android:id=”@+id/listView1” android:layout_height=”wrap_content” android:layout_weight=”0.78” android:cacheColorHint=”#00000000”></ListView>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout4” android:layout_height=”wrap_content” android:gravity=”center_horizontal”>
        <Button android:id=”@+id/button1” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Refresh”></Button>
    </LinearLayout>
</LinearLayout>




Tampilan favorit.xml

5.      Search.java
package com.mm;

import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Search extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[4];

                public static int category_id = 3; // kategori yang akan di tampilkan
                public static String config_path="http://10.0.2.2/mm/";
                public static String config_url = config_path+"mm.php";                // link website
                private int num_record=10;        // default jumlah record yang ditampilkan
                private String prov_id[];
                private ListView lv;
                private Button refresh, cari;
                private EditText etex;
                private Context ctx = this;
               
               
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
       
        etex=(EditText)findViewById(R.id.editText1);
        cari=(Button)findViewById(R.id.bcari);
        cari.setOnClickListener(this);
        
        lv = (ListView) findViewById(R.id.listView1);
                                refresh = (Button)findViewById(R.id.button1);
                                refresh.setOnClickListener(this);
                               
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
                System.out.println(i);
       }
       
        lv.setOnItemClickListener(new OnItemClickListener() {                                                                        
                                                @Override
                                                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                                                                long arg3) {
                                                                if(prov_id != null){
                                                                                Toast.makeText(getApplicationContext(),
                                                                                ((TextView) arg1).getText()+" - "+arg2, Toast.LENGTH_SHORT).show();
                                                                                Menuset.id= prov_id[arg2];
                                                                                startActivity(new Intent(ctx, Menuset.class));
                                                                }
                                                }
                                });
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==cari){
                                                getData(etex.getText().toString());
                                                lv.setTextFilterEnabled(true);
                                }
                               
                }
               
                public void getData(String id) {
                                String data[] = { "Tidak Ada Data" };
                                try {
                                                URL url = new URL(config_url + "?f=11&c=" + id+"&m="+num_record);
                                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                                DocumentBuilder db = dbf.newDocumentBuilder();
                                                Document doc = db.parse(new InputSource(url.openStream()));
                                                doc.getDocumentElement().normalize();
                                                NodeList nodeList = doc.getElementsByTagName("item");
                                                data = new String[nodeList.getLength()];
                                                prov_id = new String[nodeList.getLength()];
                                                for (int i = 0; i < nodeList.getLength(); i++) {
                                                                Node node = nodeList.item(i);
                                                                Element fstElmnt = (Element) node;
                                                                NodeList nameList = fstElmnt.getElementsByTagName("title");
                                                                Element nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                data[i] = ((Node) nameList.item(0)).getNodeValue();
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("link");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                prov_id[i]= ((Node) nameList.item(0)).getNodeValue();
                                                                                                               
                                                }
                                                if(nodeList.getLength()==0){
                                                                prov_id=null;
                                                }
                                } catch (Exception e) {
                                                // TODO: handle exception
                                }

                                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_list_item_1, data);
                                lv.setAdapter(adapter);
                }
}


6.      search.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1" android:background="@drawable/latar">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/bt_home" android:src="@drawable/agt_home" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_favo" android:src="@drawable/e" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_search" android:src="@drawable/c" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_prov" android:src="@drawable/a" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1" android:gravity="center_vertical" android:layout_weight="0.07">
        <EditText android:id="@+id/editText1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content">
            <requestFocus></requestFocus>
        </EditText>
        <Button android:layout_height="wrap_content" android:id="@+id/bcari" android:text="Cari" android:layout_weight="0.10" android:layout_width="70dp"></Button>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout3" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="0.92">
        <ListView android:layout_width="match_parent" android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_weight="0.78" android:cacheColorHint="#00000000"></ListView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout4" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Refresh"></Button>
    </LinearLayout>
</LinearLayout>



Tampilan search.xml

7.      Provinsy.xml
package com.mm;

import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Provinsy extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[4];
                public static int category_id = 3; // kategori yang akan di tampilkan
                public static String config_path="http://10.0.2.2/mm/";
                public static String config_url = config_path+"mm.php";                // link website
                private int num_record=10;        // default jumlah record yang ditampilkan
                private String prov_id[];
                private ListView lv;
                private Button refresh, more;
                private Context ctx = this;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.provinsy);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
        lv = (ListView) findViewById(R.id.listView1);
                                refresh = (Button)findViewById(R.id.button1);
                                refresh.setOnClickListener(this);
                                getData();
                                lv.setTextFilterEnabled(true);                   
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
                System.out.println(i);
        }
        lv.setOnItemClickListener(new OnItemClickListener() {                                                                        
                                                @Override
                                                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                                                                long arg3) {
                                                                if(prov_id != null){
                                                                                Toast.makeText(getApplicationContext(),
                                                                                ((TextView) arg1).getText()+" - "+arg2, Toast.LENGTH_SHORT).show();
                                                                                MpDaerah.id= prov_id[arg2];
                                                                                startActivity(new Intent(ctx, MpDaerah.class));
                                                                }
                                                }
                                });
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==refresh){
                                                num_record = 10;            // refresh data 10 record pertama
                                                getData();
                                                Toast.makeText(getApplicationContext(),"Refresh Data Success!", Toast.LENGTH_SHORT).show();
                                }
                               
                }
               
                public void getData() {
                                String data[] = { "Tidak Ada Data" };
                                try {
                                                URL url = new URL(config_url + "?f=1&c=" + category_id+"&m="+num_record);
                                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                                DocumentBuilder db = dbf.newDocumentBuilder();
                                                Document doc = db.parse(new InputSource(url.openStream()));
                                                doc.getDocumentElement().normalize();
                                                NodeList nodeList = doc.getElementsByTagName("item");
                                                data = new String[nodeList.getLength()];
                                                prov_id = new String[nodeList.getLength()];
                                                for (int i = 0; i < nodeList.getLength(); i++) {
                                                                Node node = nodeList.item(i);
                                                                Element fstElmnt = (Element) node;
                                                                NodeList nameList = fstElmnt.getElementsByTagName("title");
                                                                Element nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                data[i] = ((Node) nameList.item(0)).getNodeValue();
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("link");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                prov_id[i]= ((Node) nameList.item(0)).getNodeValue();
                                                                                                               
                                                }
                                                if(nodeList.getLength()==0){
                                                                prov_id=null;
                                                }
                                } catch (Exception e) {
                                                // TODO: handle exception
                                }

                                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_list_item_1, data);
                                lv.setAdapter(adapter);
                }
}


8.      Provinsy.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1" android:background="@drawable/latar">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/bt_home" android:src="@drawable/agt_home" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_favo" android:src="@drawable/e" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_search" android:src="@drawable/c" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_prov" android:src="@drawable/a" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1" android:gravity="center_vertical" android:layout_weight="0.07">
        <EditText android:id="@+id/editText1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content">
            <requestFocus></requestFocus>
        </EditText>
        <Button android:layout_height="wrap_content" android:id="@+id/bcari" android:text="Cari" android:layout_weight="0.10" android:layout_width="70dp"></Button>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout3" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="0.92">
        <ListView android:layout_width="match_parent" android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_weight="0.78" android:cacheColorHint="#00000000"></ListView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout4" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Refresh"></Button>
    </LinearLayout>
</LinearLayout>


Tampilan propinsi.xml

9.      MpDaerah.java
package com.mm;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MpDaerah extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[4];
                public static int category_id = 3; // kategori yang akan di tampilkan
                public static String config_path="http://10.0.2.2/mm/";
                public static String config_url = config_path+"mm.php";                // link website
                public static String id;
                private int num_record=10;        // default jumlah record yang ditampilkan
                private String prov_id[];
                private ListView lv;
                private Button refresh, more;
                private Context ctx = this;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mpdaerah);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
        lv = (ListView) findViewById(R.id.listView1);
                                refresh = (Button)findViewById(R.id.button1);
                                refresh.setOnClickListener(this);
                                getData();
                                lv.setTextFilterEnabled(true);                   
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
                System.out.println(i);
        }
        lv.setOnItemClickListener(new OnItemClickListener() {                                                                        
                                                @Override
                                                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                                                                long arg3) {
                                                                if(prov_id != null){
                                                                                Toast.makeText(getApplicationContext(),
                                                                                ((TextView) arg1).getText()+" - "+arg2, Toast.LENGTH_SHORT).show();
                                                                                Menuset.id= prov_id[arg2];
                                                                                startActivity(new Intent(ctx, Menuset.class));
                                                                }
                                                }
                                });
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Search.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==refresh){
                                                num_record = 10;            // refresh data 10 record pertama
                                                getData();
                                                Toast.makeText(getApplicationContext(),"Refresh Data Success!", Toast.LENGTH_SHORT).show();
                                }
                               
                }
               
                public void getData() {
                                String data[] = { "Tidak Ada Data" };
                                try {
                                                URL url = new URL(config_url + "?f=9&c=" + id+"&m="+num_record);
                                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                                DocumentBuilder db = dbf.newDocumentBuilder();
                                                Document doc = db.parse(new InputSource(url.openStream()));
                                                doc.getDocumentElement().normalize();
                                                NodeList nodeList = doc.getElementsByTagName("item");
                                                data = new String[nodeList.getLength()];
                                                prov_id = new String[nodeList.getLength()];
                                                for (int i = 0; i < nodeList.getLength(); i++) {
                                                                Node node = nodeList.item(i);
                                                                Element fstElmnt = (Element) node;
                                                                NodeList nameList = fstElmnt.getElementsByTagName("title");
                                                                Element nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                data[i] = ((Node) nameList.item(0)).getNodeValue();
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("link");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                prov_id[i]= ((Node) nameList.item(0)).getNodeValue();
                                                                                                               
                                                }
                                                if(nodeList.getLength()==0){
                                                                prov_id=null;
                                                }
                                } catch (Exception e) {
                                                // TODO: handle exception
                                }

                                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_list_item_1, data);
                                lv.setAdapter(adapter);
                }
}



10.    Mpdaerah.xml
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    android:orientation=”vertical”
    android:layout_width=”fill_parent”
    android:layout_height=”fill_parent”
    android:weightSum=”1” android:background=”@drawable/latar”>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout1” android:layout_height=”wrap_content” android:gravity=”center_horizontal”>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/bt_home” android:src=”@drawable/agt_home” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_favo” android:src=”@drawable/e” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_search” android:src=”@drawable/c” android:layout_height=”wrap_content”></ImageButton>
        <ImageButton android:layout_width=”wrap_content” android:id=”@+id/btn_prov” android:src=”@drawable/a” android:layout_height=”wrap_content”></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout2” android:layout_height=”wrap_content” android:weightSum=”1” android:gravity=”center_vertical” android:layout_weight=”0.07”>
        <TextView android:layout_width=”wrap_content” android:textAppearance=”?android:attr/textAppearanceMedium” android:id=”@+id/textView1” android:layout_height=”wrap_content” android:text=”Pilih : “ android:textColor=”#ffffff”></TextView>
        <TextView android:textAppearance=”?android:attr/textAppearanceMedium” android:id=”@+id/textView2” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:textColor=”#ffffff” android:text=”Menu”></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout3” android:layout_height=”wrap_content” android:orientation=”vertical” android:layout_weight=”0.92”>
        <ListView android:layout_width=”match_parent” android:id=”@+id/listView1” android:layout_height=”wrap_content” android:layout_weight=”0.78” android:cacheColorHint=”#00000000”></ListView>
    </LinearLayout>
    <LinearLayout android:layout_width=”match_parent” android:id=”@+id/linearLayout4” android:layout_height=”wrap_content” android:gravity=”center_horizontal”>
        <Button android:id=”@+id/button1” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Refresh”></Button>
    </LinearLayout>
</LinearLayout>


Gambar tampilan mpdaerah.xml

11.  Menuset.java
package com.mm;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class Menuset extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
                ImageButton []a=new ImageButton[4];
                public static int category_id = 3; // kategori yang akan di tampilkan
                public static String config_path="http://10.0.2.2/mm/";
                public static String config_url = config_path+"mm.php";                // link website
                public static String id;
                private int num_record=10;        // default jumlah record yang ditampilkan
                private String prov_id[];
                private TextView t0,t1,t2;
                private Button refresh, more;
                private Context ctx = this;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menuset);
        a[0]=(ImageButton)findViewById(R.id.bt_home);
        a[1]=(ImageButton)findViewById(R.id.btn_favo);
        a[2]=(ImageButton)findViewById(R.id.btn_search);
        a[3]=(ImageButton)findViewById(R.id.btn_prov);
        t0 = (TextView) findViewById(R.id.tnama_m);
        t1 = (TextView) findViewById(R.id.tbahan);
        t2 = (TextView) findViewById(R.id.tcara);
        getData();
                                //lv.setTextFilterEnabled(true);                               
        for(int i=0;i<a.length;i++){
                a[i].setOnClickListener(this);
                System.out.println(i);
       }
       
     
    }
                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(v==a[0]){
                                                Intent mm=new Intent().setClass(this, MmActivity.class);
                                                startActivity(mm);
                                }
                                if(v==a[1]){
                                                Intent mm=new Intent().setClass(this, Favorit.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[2]){
                                                Intent mm=new Intent().setClass(this, Menuset.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                                if(v==a[3]){
                                                Intent mm=new Intent().setClass(this, Provinsy.class);
                                                startActivity(mm);
                                                //setContentView(R.layout.cari);
                                }
                               
                }
               
                public void getData() {
                                String data[] = { "Tidak Ada Data" };
                                try {
                                                URL url = new URL(config_url + "?f=10&c=" + id+"&m="+num_record);
                                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                                DocumentBuilder db = dbf.newDocumentBuilder();
                                                Document doc = db.parse(new InputSource(url.openStream()));
                                                doc.getDocumentElement().normalize();
                                                NodeList nodeList = doc.getElementsByTagName("item");
                                                data = new String[nodeList.getLength()];
                                                prov_id = new String[nodeList.getLength()];
                                                for (int i = 0; i < nodeList.getLength(); i++) {
                                                                Node node = nodeList.item(i);
                                                                Element fstElmnt = (Element) node;
                                                               
                                                                NodeList nameList = fstElmnt.getElementsByTagName("title");
                                                                Element nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                data[i] = ((Node) nameList.item(0)).getNodeValue();
                                                                t0.setText(data[i]);
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("bahan");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                String l1= ((Node) nameList.item(0)).getNodeValue();
                                                                t1.setText(l1);
                                                               
                                                                nameList = fstElmnt.getElementsByTagName("description");
                                                                nameElement = (Element) nameList.item(0);
                                                                nameList = nameElement.getChildNodes();
                                                                String l2= ((Node) nameList.item(0)).getNodeValue();
                                                                t2.setText(l2);  
                                                }
                                                if(nodeList.getLength()==0){
                                                                prov_id=null;
                                                }
                                } catch (Exception e) {
                                                // TODO: handle exception
                                }                             
                }             
}


12.  menuset.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1" android:background="@drawable/latar">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <ImageButton android:layout_width="wrap_content" android:id="@+id/bt_home" android:src="@drawable/agt_home" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_favo" android:src="@drawable/e" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_search" android:src="@drawable/c" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/btn_prov" android:src="@drawable/a" android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>
    <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_weight="0.84" android:weightSum="1">
        <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:id="@+id/tnama_m" android:textColor="#ffffff"></TextView>
        <TextView android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:text="Bahan" android:id="@+id/texts" android:textColor="#ffffff"></TextView>
        <ScrollView  
        android:id="@+id/ScrollView01" 
      android:layout_width="fill_parent" android:layout_height="60dp" android:layout_weight="0.22"> 
          
       <TextView  
       android:layout_height="wrap_content"  
       android:layout_width="wrap_content"  
       android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" android:id="@+id/tbahan"/> 
     </ScrollView>
        <TextView android:id="@+id/textView3" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:text="Cara Pembuatan" android:textColor="#ffffff"></TextView>
        <ScrollView android:layout_height="60dp" android:layout_width="fill_parent" android:id="@+id/ScrollView02" android:layout_weight="0.50">
            <TextView android:layout_width="wrap_content" android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" android:layout_height="136dp" android:id="@+id/tcara"></TextView>
        </ScrollView> 
    </LinearLayout>
</LinearLayout>



Gambar tampilan menuset.xml

13.   AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mm"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MmActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Favorit"></activity>
        <activity android:name="Provinsy"></activity>
        <activity android:name="Search"></activity>
        <activity android:name="MpDaerah"></activity>
        <activity android:name="Menuset"></activity>

    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>





2 komentar:

Mantap tuh source codenya. Dimana /gimana cara saya source code tsb, Terima kasih

Post a Comment