1
2
3
4
5
6
7
8
9
| create databases m-resto; use m-resto; CREATE TABLE `kategori` ( `id` int( 6 ) unsigned NOT NULL AUTO_INCREMENT, `name` varchar( 32 ) COLLATE utf 8 _unicode_ci NOT NULL, `contains` int( 6 ) NOT NULL, PRIMARY KEY (`id`) ); |
kalau anda tidak terbiasa dengan sintaks sql…silahkan buat dengan visual phpmyadmin or sqlyog, mysqlfront atau soft visual database mysql lainnya.
Untuk kategori produks dalam restoran kita misalkan Makanan,Minuman dan snack..masukkan data-data tersebut dengan perintah berikut :
1
| insert into `kategori`(`id`,`name`,`contains`) values ( 1 , 'Makanan' , 3 ),( 2 , 'Minuman' , 4 ),( 3 , 'Snack' , 4 ); |
note : gunakan teknik visual alias drag en drop apabila anda tidak hapal betul dengan codingan.
berikut adalah codingan utk desain main.xml gambar diatas.
main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| <?xml version= "1.0" encoding= "utf-8" ?> <AbsoluteLayout android:id= "@+id/AbsoluteLayout01" android:layout_width= "fill_parent" android:layout_height= "fill_parent" xmlns:android= "http://schemas.android.com/apk/res/android" > <TextView android:id= "@+id/textView1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_x= "28dp" android:layout_y= "10dp" android:text= "SELAMAT DATANG DI M-RESTO" /> <Spinner android:id= "@+id/Spinner01" android:layout_width= "200dip" android:layout_height= "wrap_content" android:layout_x= "33dp" android:layout_y= "80dp" /> <TextView android:id= "@+id/textView2" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_x= "37dp" android:layout_y= "55dp" android:text= "SILAHKAN PILIH KATEGORI" /> </AbsoluteLayout> |
kita memerlukan 2 file java sebagai berikut :
GetData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
| package wilis.resto; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.DefaultHttpClient; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.Spinner; public class GetData extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); fetch(); } public void fetch() { HttpClient httpclient = new DefaultHttpClient(); HttpRequestBase httpRequest = null; HttpResponse httpResponse = null; InputStream inputStream = null; String response = "" ; StringBuffer buffer = new StringBuffer(); httpRequest = new HttpGet( url ); try { httpResponse = httpclient.execute(httpRequest); } catch (ClientProtocolException e 1 ) { e 1 .printStackTrace(); } catch (IOException e 1 ) { e 1 .printStackTrace(); } try { inputStream = httpResponse.getEntity().getContent(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } byte[] data = new byte[ 512 ]; int len = 0 ; try { while ( -1 != (len = inputStream.read(data)) ) { buffer.append(new String(data, 0 , len)); } } catch (IOException e) { e.printStackTrace(); } try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } response = buffer.toString(); StringParser parser = new StringParser(); ArrayList<Object> output = parser.Parse(response); Object[] Output = output.toArray(); String[] content = new String[Output.length]; for (int i= 0 ;i<content.length;i++) { content[i] = Output[i].toString(); } Spinner spinner = (Spinner)findViewById(R.id.Spinner 01 ); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, content); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); } } 1 StringParser.java 1 package wilis.resto; import java.util.ArrayList; public class StringParser { public StringParser() { } public ArrayList<Object> Parse(String input) { ArrayList<Object> output = new ArrayList<Object>(); int pointer = 0 ; String data = "" ; while ( pointer <= input.length() -1 ) { if (input.charAt( pointer ) == '#' ) { output.add(data); data = "" ; pointer ++; } if ( pointer < input.length()) { data+= input.charAt( pointer ); } pointer ++; } return output; } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <?xml version= "1.0" encoding= "utf-8" ?> <manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "wilis.resto" android:versionCode= "1" android:versionName= "1.0" > <uses-sdk android:minSdkVersion= "9" /> <uses-permission android:name= "android.permission.INTERNET" /> <application android: icon = "@drawable/ic_launcher" android:label= "@string/app_name" > <activity android:label= "@string/app_name" android:name= ".GetData" > <intent-filter > <action android:name= "android.intent.action.MAIN" /> <category android:name= "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| <!--?php <br ?--> $db_host = "localhost" ; $db_name = "m-resto" ; $db_user = "root" ; $db_password = "" ; extract($_REQUEST, EXTR_OVERWRITE); mysql_connect($db_host, $db_user, $db_password) or die ( "fail connect." ); mysql_select_db($db_name); if ($ct == "SEL_Kategori" ) { $sqlSEL = " SELECT * FROM kategori " ; $hasil = mysql_query($sqlSEL); $kirim = "" ; while ($data = mysql_fetch_array($hasil)) { $id = stripslashes($data[id]); $nama= stripslashes($data[name]); $jml = stripslashes($data[contains]); $kirim .= $id. "." .$nama . "#" ; } echo $kirim; } // proc lainnya... // ?? |
Tampilan awal
Tampilan jika kategori minuman di pilih
Sedikit Info.
Dapatkan Pembahasan full dan source code lengkap aplikasi m-resto di buku yang akan terbit bulan ini..
Pembahasan : M-Learning berbasis android, Aplikasi Hadits, Aplikasi doa harian islam, m-resto dan banyak aplikasi lainnya…bahasan full dan source code full bukan setengah2..
uxc.wilis
Post a Comment