在我的logcat中,我返回了一些数组,我想在android列表视图中列出它们,我不知道它是如何工作的,因为我是这个android东西的新手
thnx提前:)
我的php代码:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "android_sms";
date_default_timezone_set('Asia/Singapore');
$date=date('Y-m-d');
$time=date('H:i:s');
$returnVal = array();
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
//$sql = "select * from sample order by time desc limit 1";
$sql = "select * from sample";
$res = $conn->query($sql);
while($row =$res->fetch_assoc()){
$d = array();
foreach($row as $key=>$val){
$d[] = $row;
$returnVal["data"][]=$val;
}
}
print_r($returnVal["data"]);
}
$conn->close();
?>
我的安卓代码:
@Override
protected Void doInBackground(Void... arg0) {
try{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("message",message));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost= new HttpPost("http://192.168.0.111/android/dbselect.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
//httpclient.execute(httppost);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String responseStr = EntityUtils.toString(entity);
Log.e("LOGsadasd", responseStr);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
在我的日志中,我返回这些数组
Array
(
[0] => 5
[1] => niko
[2] => 2015-02-13 13:54:24
[3] => 6
[4] => noel
[5] => 2015-02-13 14:23:34
[6] => 7
[7] => santos
[8] => 2015-02-13 14:35:09
)
如何在列表视图中取消显示它们?tnx提前
您应该编写一个web服务来读取web上的数据。之后,您的post或get方法应该返回JSON字符串。您可以很容易地读取应用程序中的值。这些链接将有助于
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php