【问题标题】:Display received data from .php script in ListView在 ListView 中显示从 .php 脚本接收到的数据
【发布时间】:2013-08-16 14:12:20
【问题描述】:

如何使用 Android 代码将数据库表中的数据放入listView

这是 PHP 代码,我需要 Android 代码:

$your_querry="select * from member ";
$query=mysql_query($your_querry);
$list=array();
while($row=mysql_fetch_assoc($query))
{
    $list[]=$row;
}

echo json_encode($list);

【问题讨论】:

  • 这个过程有很多步骤。您需要 (1) 使用 AsyncTask 从服务器下载该信息 (2) 处理您获得的 JSON (3) 创建一个列表适配器,将这些信息加载到其中 - 有很多关于如何设置列表的教程在谷歌上查看你可以找到但是这里有太多的步骤来真正给出一个好的答案

标签: php android json http android-listview


【解决方案1】:

对于这个问题,请使用 JSONParser.java 和 ListAdapter.java ,

如果您的列表视图包含图像,我强烈建议您使用

1-MemoryCache.java.
2-FileCache.java.
3-ImageLoader.java.
4-Utils.java.

这就是我的想法

【讨论】:

    【解决方案2】:

    试试这样的

    DefaultHttpClient   httpclient = new DefaultHttpClient(new BasicHttpParams());
    HttpGet httppost = new HttpGet("path/to/your/php-script");
    
    httpGet.setHeader("Content-type", "application/json");
    
    InputStream inputStream = null;
    String result = null;
    try {
        HttpResponse response = httpclient.execute(httppost);           
        HttpEntity entity = response.getEntity();
    
        inputStream = entity.getContent();
    
        // Now parse the JSON with some JSON library like Jackson, Gson or JSON.org
        ...
        // Then fill the listView with the objects you parsed
        ...
    

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2012-08-28
      • 1970-01-01
      • 2019-11-15
      相关资源
      最近更新 更多