Sie sind auf Seite 1von 10

ANDROID

HTTPCLIENT & PHP


MYSQL
28Feb - 1Mar 2011

Special Course

Outline
Day 1
Get Start and Setup tool
Create Simple application
Simple Connect PHP MySQL: select

Day 2
Simple Connect PHP MySQL: select
insert update delete
ListView UI
Android: HTTPCLIENT & PHP MYSQL 28 Feb
2
- 1 Mar
Example

Android: HTTPCLIENT & PHP MYSQL 28 Feb


3
- 1 Mar
Get Start
Install SDK
Install ADT in eclipse
Create simple application Hello World
Android File & Folder: R.java
manifestfile.xml layout.xml
Basic UI
How to use Simulator

Android: HTTPCLIENT & PHP MYSQL 28 Feb


4
- 1 Mar
Simple Application
Activity
method: onCreate
findViewByID

Android: HTTPCLIENT & PHP MYSQL 28 Feb


5
- 1 Mar
Connect PHP MySQL
Overview
Select
request
Insert
response Connect DB

Update
MySQL
Delete

Android: HTTPCLIENT & PHP MYSQL 28 Feb


6
- 1 Mar
HttpClient (code)
//connect
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpRespose = httpClient.execute(httpPost);
HttpEntity httpEntity = httpRespose.getEntity();
//read content
InputStream in = httpEntity.getContent();
BufferedReader read = new BufferedReader(new InputStreamReader(in));
String content = "";
String line = "";
while((line = read.readLine())!=null){
content += line;
}

Android: HTTPCLIENT & PHP MYSQL 28 Feb


7
- 1 Mar
Post Parameter
Overview
Key + value $w = $_REQUEST[whereId]
param.add(new BasicNameValuePair("whereId", "19")); or
$w = $_POST[whereId]
NameValuePair
Request+parameter
Insert

response

Update
Android: HTTPCLIENT & PHP MYSQL 28 Feb
8
- 1 Mar
Post Parameter (code)
ArrayList<NameValuePair> param = new
ArrayList<NameValuePair>();
//test select: whereId
param.add(new BasicNameValuePair("whereId", "19"));

//add parameter
httpPost.setEntity(new UrlEncodedFormEntity(param));

Android: HTTPCLIENT & PHP MYSQL 28 Feb


9
- 1 Mar
Thank
You.

Android: HTTPCLIENT & PHP MYSQL 28 Feb


10
- 1 Mar

Das könnte Ihnen auch gefallen