Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将数组从php显示到android listview?_Php_Android_Arrays_Listview - Fatal编程技术网

如何将数组从php显示到android listview?

如何将数组从php显示到android listview?,php,android,arrays,listview,Php,Android,Arrays,Listview,在我的logcat中,我返回了一些数组,我想在android listview中列出它们,我不知道它是如何工作的,因为我对android的东西还不熟悉 thnx提前:) 我的php代码: <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "android_sms"; date_default_timezone_set('Asia/Singapore'); $date=date(

在我的logcat中,我返回了一些数组,我想在android listview中列出它们,我不知道它是如何工作的,因为我对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();

?>
如何在列表视图中显示它们?
tnx提前

您应该编写一个web服务来读取web上的数据。之后,post或get方法应返回JSON字符串。您可以轻松读取应用程序中的值。这些链接将有所帮助


您需要以可用格式发送。例如,作为JSON-
echo JSON_encode($returnVal['data'])
@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
)